题解

173 条题解

  • 0
    @ 2015-10-18 17:41:37

    do
    begin
    if (a[i]=x )then begin find:=true; exit; end;
    end;
    find:=false;
    end;
    begin
    count:=0;
    readln(n);
    for i:=1 to n do
    read(a[i]);
    // bubbleSort(a);

    for i:=1 to n do
    for j:=i+1 to n do
    begin k:= a[i]+a[j];
    if find(a,k)=true then inc(count);
    end;
    writeln(count);
    readln(k);
    end.

  • 0
    @ 2015-10-12 08:05:58

    include<iostream> include<cstring>

    using namespace std;
    int a[11000];
    bool an[44100];
    int main()
    {
    int i,j,k,n,s=0;
    cin>>n;
    memset(an,false,sizeof(an));
    for(i=1;i<=n;i++)
    cin>>a[i];
    for(i=1;i<=n;i++)
    {
    for(j=1;j<=n;j++)
    {
    for(k=j+1;k<=n;k++)
    {
    if(a[j]+a[k]==a[i]&&an[i]==false)
    {
    s++;
    an[i]=true;
    }
    }
    }
    }
    cout<<s;
    return 0;
    }

  • 0
    @ 2015-10-12 08:05:56

    include<iostream> include<cstring>

    using namespace std;
    int a[11000];
    bool an[44100];
    int main()
    {
    int i,j,k,n,s=0;
    cin>>n;
    memset(an,false,sizeof(an));
    for(i=1;i<=n;i++)
    cin>>a[i];
    for(i=1;i<=n;i++)
    {
    for(j=1;j<=n;j++)
    {
    for(k=j+1;k<=n;k++)
    {
    if(a[j]+a[k]==a[i]&&an[i]==false)
    {
    s++;
    an[i]=true;
    }
    }
    }
    }
    cout<<s;
    return 0;
    }

  • 0
    @ 2015-10-12 08:05:53

    include<iostream> include<cstring>

    using namespace std;
    int a[11000];
    bool an[44100];
    int main()
    {
    int i,j,k,n,s=0;
    cin>>n;
    memset(an,false,sizeof(an));
    for(i=1;i<=n;i++)
    cin>>a[i];
    for(i=1;i<=n;i++)
    {
    for(j=1;j<=n;j++)
    {
    for(k=j+1;k<=n;k++)
    {
    if(a[j]+a[k]==a[i]&&an[i]==false)
    {
    s++;
    an[i]=true;
    }
    }
    }
    }
    cout<<s;
    return 0;
    }

  • 0
    @ 2015-10-12 08:05:49

    include<iostream> include<cstring>

    using namespace std;
    int a[11000];
    bool an[44100];
    int main()
    {
    int i,j,k,n,s=0;
    cin>>n;
    memset(an,false,sizeof(an));
    for(i=1;i<=n;i++)
    cin>>a[i];
    for(i=1;i<=n;i++)
    {
    for(j=1;j<=n;j++)
    {
    for(k=j+1;k<=n;k++)
    {
    if(a[j]+a[k]==a[i]&&an[i]==false)
    {
    s++;
    an[i]=true;
    }
    }
    }
    }
    cout<<s;
    return 0;
    }

  • 0
    @ 2015-10-12 07:39:41

    #include<iostream>
    #include<cstring>
    using namespace std;
    int a[11000];
    bool an[44100];
    int main()
    {
    int i,j,k,n,s=0;
    cin>>n;
    memset(an,false,sizeof(an));
    for(i=1;i<=n;i++)
    cin>>a[i];
    for(i=1;i<=n;i++)
    {
    for(j=1;j<=n;j++)
    {
    for(k=j+1;k<=n;k++)
    {
    if(a[j]+a[k]==a[i]&&an[i]==false)
    {
    s++;
    an[i]=true;
    }
    }
    }
    }
    cout<<s;
    return 0;
    }

  • 0
    @ 2015-10-03 18:11:59

    水题一发
    #include<cstdio>
    #include<iostream>
    #include<cstring>
    using namespace std;
    int a[11000];
    bool an[44100];
    int main()
    {
    int i,j,k,n,s=0;
    scanf("%d",&n);
    memset(an,false,sizeof(an));
    for(i=1;i<=n;i++)scanf("%d",&a[i]);
    for(i=1;i<=n;i++)
    {
    for(j=1;j<=n;j++)
    {
    for(k=j+1;k<=n;k++)
    {
    if(a[j]+a[k]==a[i]&&an[i]==false)
    {
    s++;
    an[i]=true;
    }
    }
    }
    }
    printf("%d\n",s);
    return 0;
    }

  • 0
    @ 2015-09-13 19:58:44

    神题目 楼下说的就是这个题目的坑人之处 1+4=5与2+3=5是一组!!!
    无语了

  • 0
    @ 2015-09-07 21:00:12

    题目有坑,1+4=5与2+3=5是一组!!!
    我也被坑了
    #include<stdio.h>
    #include<stdlib.h>
    int a[110];
    int n;
    int num=0;
    int v[110];
    int main()
    {
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    scanf("%d",&a[i]);
    for(int i=1;i<n;i++)
    for(int j=i+1;j<=n;j++)
    for(int k=1;k<=n;k++)
    if(k!=i&&k!=j&&a[i]+a[j]==a[k]&&v[k]==0)
    {
    num++;
    v[k]=1;
    }
    printf("%d",num);
    //system("pause");
    return 0;
    }

  • 0
    @ 2015-08-19 21:44:19

    //难度几乎为0,但一定要注意:问的是个数而不是方案数!!一定要注意。本人去年竞赛,就因为这个点没搞清楚,才痛失一等奖!

    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <iostream>
    using namespace std;

    int n,a[110],flag[10010],ans=0;

    int cmp(const void *a,const void *b)
    {
    return *(int )a>(int *)b?1:-1;
    }

    int main()
    {
    scanf("%d\n",&n);
    for(int i=1;i<=n;i++)
    {
    scanf("%d ",&a[i]);
    }
    qsort(a+1,n,sizeof(a[1]),cmp);
    memset(flag,0,sizeof(flag));
    for(int i=1;i<=n;i++)
    {
    for(int j=i+1;j<=n;j++)
    {
    for(int k=j+1;k<=n;k++)
    {
    if(a[i]+a[j]==a[k]&&a[i]!=a[k]) flag[a[k]]=1;
    }
    }
    }
    for(int i=1;i<=n;i++)
    {
    if(flag[a[i]]==1) ans++;
    }
    printf("%d\n",ans);
    return 0;
    }

  • 0
    @ 2015-08-16 22:30:54

    无难度水题
    var n,i,j,c,x:longint;
    a,s:array[1..10000]of integer;
    begin
    read(n);
    for i:=1 to n do read(a[i]);
    for i:=1 to n do
    for j:=i+1 to n do begin
    inc(c);s[c]:=a[i]+a[j];
    end;
    for i:=1 to c do
    for j:=1 to n do
    if s[i]=a[j] then begin a[j]:=0;inc(x);break;end;
    write(x);
    end.

  • 0
    @ 2015-08-03 15:10:09

    #include<cstdio>
    #include<iostream>
    using namespace std;
    int n,a[110];
    bool flag[10010];
    int main()
    {
    int i,j,k,ans=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++) scanf("%d",&a[i]);
    for(i=1;i<=n;i++) flag[a[i]]=1;
    for(i=1;i<=n;i++)
    for(j=i+1;j<=n;j++)
    if(a[i]+a[j]<=10000 && flag[a[i]+a[j]])
    flag[a[i]+a[j]]=0,ans++;
    printf("%d\n",ans);
    return 0;
    }

  • 0
    @ 2015-06-25 17:35:02

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<cstdlib>
    using namespace std;
    int a[102];
    bool t[200001];
    int i,ans,n,j;
    int main()
    {
    memset(t,0,sizeof(t));
    a[0]=0;ans=0;
    cin>>n;
    for(i=1;i<=n;i++) cin>>a[i];
    for(i=1 ;i<=n-1;i++)
    for(j=i+1;j<=n;j++)
    t[a[i]+a[j]]=1;
    for(i=1;i<=n;i++)
    if (t[a[i]]) ans=ans+1;
    cout<<ans<<endl;
    return 0;
    }

  • 0
    @ 2015-06-09 13:59:59

    简单枚举而已 亲注意 最好用longint不然 容易超
    program shaoziwei;
    var
    a:array[1..200] of longint;
    b:array[1..200] of longint;
    temp,num,i,m,q,sign:**longint**;
    begin
    for i:=1 to 100 do
    b[i]:=0;
    sign:=0;
    read(num);
    for i:=1 to num do
    read(a[i]);
    for i:=1 to num-1 do
    for m:=i+1 to num do
    begin
    temp:=a[i]+a[m];
    for q:=1 to num do
    if (temp=a[q])and(b[q]=0) then
    begin
    sign:=sign+1;
    b[q]:=1;
    break;
    end;
    end;
    write(sign);
    end.

  • 0
    @ 2015-02-01 09:14:55

    注意两种问法:有几对数和为另一个数;
    有几个数为另两个数的和。
    #include<iostream>
    #include<string.h>
    using namespace std;
    bool has[10003];
    int a[103];
    int main(){
    //freopen("in.txt", "r", stdin);
    int size;
    cin >> size;
    int i;
    memset(has, 0, sizeof(has));
    for (i = 0; i < size; i++){
    cin >> a[i];
    has[a[i]] = true;
    }
    int ans = 0;
    int j;
    for (i = 0; i < size; i++){
    for (j = i+1; j < size; j++){
    if (a[i] + a[j] <= 10000){
    if (has[a[i] + a[j]]){
    ans++;
    has[a[i] + a[j]] = false;
    }
    }
    }
    }
    cout << ans << endl;
    return 0;
    }

  • 0
    @ 2015-01-18 16:04:52

    //其中有多少个数,恰好等于集合中另外两个(不同的)数之和?
    //注意
    //5
    //1 2 3 4 5
    //其中1+4=5,2+3=5,但5只能算作一次哦!!!
    #include<iostream>
    #include<string.h>

    using namespace std;

    int a[101];
    bool flag[101];

    int main()
    {
    int n, i, j, k, tot;

    cin >> n;
    memset(a,0,sizeof(a));
    memset(flag,false,sizeof(flag));

    tot = 0;

    for(i = 1; i <= n; i++)
    cin >> a[i];

    for(i = 1; i < n; i++)
    for(j = i+1; j <= n; j++)
    {
    int temp = a[i] + a[j];
    for(k = 1; k <= n; k++)
    {
    if((k != i) && (k != j) && (temp == a[k])) flag[k] = true;
    }
    }

    for (i = 1; i <= n; i++)
    if(flag[i]) tot++;
    cout << tot << endl;

    return 0;
    }

  • 0
    @ 2015-01-08 10:52:11

    晕死,没看好题目,原来和等于集合的数那个数只能算一次,不是算组合个数而是算数个个数,脑残了实在是。
    诶- -下次做题看来要细心点

    因为数据很小,枚举的话绝对不会爆的。要是数据大了的话,这道题可以变得比较复杂!
    ###block code
    program ex;
    var n,i,ans,j,sum,k:longint;
    data:array[1..100] of longint;
    ps:array[1..100] of boolean;
    begin
    fillchar(ps,sizeof(ps),false);
    read(n); ans:=0;
    for i:=1 to n do
    read(data[i]);

    for i:=1 to n-1 do
    for j:=i+1 to n do
    begin
    sum:=data[i]+data[j];
    for k:=1 to n do
    if (sum=data[k]) and (ps[k]=false) then
    begin
    inc(ans);
    ps[k]:=true;
    break;
    end;
    end;

    write(ans);
    end.

  • 0
    @ 2015-01-04 19:11:17

    代码
    #include<iostream>
    #include<algorithm>
    #include<math.h>
    #include<string.h>
    #include<stdio.h>
    #include<stdlib.h>
    using namespace std;
    bool cmp(int a,int b)
    {
    if(a>b)return 1;
    return 0;
    }
    int a[10000];
    int main()
    {
    int n,ans=0;
    cin>>n;
    for(int i=0;i<n;i++)
    cin>>a[i];
    sort(a,a+n,cmp);
    for(int i=0;i<n-1;i++)
    {
    int y=i,z=n;
    while(a[y+1]!=a[z-1]&&a[y+1]!=0&&a[z-1]!=0)
    {
    if(a[i]==a[y+1]+a[z-1]){
    ans++;

    break;
    }
    else if(a[i]>a[y+1]+a[z-1])z--;
    else if(a[i]<a[y+1]+a[z-1])y++;

    }
    }
    cout<<ans<<endl;

    return 0;
    }

  • 0
    @ 2014-12-27 11:14:07

    O(max*n)

    Pascal Code

    var
    n,t,s,i,j:longint;
    num:array[1..10000] of boolean;
    num2:array[1..10000] of longint;
    flag:array[1..10000] of boolean;
    begin
    readln(n);
    for i:=1 to n do
    begin
    read(t);
    num2[i]:=t;
    num[t]:=true;
    end;
    fillchar(flag,sizeof(flag),0);
    for i:=1 to n do
    for j:=1 to num2[i]-1 do
    if (num[j]) and (num[num2[i]-j]) and (num2[i]-j<>j) and not (flag[i]) then
    begin
    s:=s+1;
    flag[i]:=true;
    end;
    writeln(s);
    end.

  • 0
    @ 2014-12-15 22:05:51

    #include<iostream>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    int a[100+5],n,ans;
    bool ok[100];
    int main()
    {
    memset(ok,false,sizeof(ok));
    cin>>n;
    for(int i=1;i<=n;i++){cin>>a[i];}
    sort(a+1,a+n+1);
    for(int i=n;i>=1;i--)
    {
    for(int j=1;j<=i;j++)
    {
    for(int k=j+1;k<=i;k++)
    {
    if(a[i]==a[j]+a[k]&&a[j]!=a[k]&&ok[i]==false){ans++;ok[i]=true;}
    }
    }
    }
    cout<<ans<<endl;
    return 0;
    }

信息

ID
1911
难度
6
分类
(无)
标签
递交数
17097
已通过
4518
通过率
26%
被复制
28
上传者