题解

173 条题解

  • 0
    @ 2016-11-17 17:19:38

    求解释为什么RE?
    #include<cstdio>
    using namespace std;
    int n,a[101],ans;
    bool b[101];
    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=1;j<=n;j++)
    {
    if(i!=j)
    b[a[i]+a[j]]=true;
    }
    for(int i=1;i<=n;i++)
    if(b[a[i]])
    ans++;
    printf("%d",ans);
    return 0;
    }

    • @ 2016-11-28 14:12:26

      a[i] <= 10000
      bool b[20001]才对

  • 0
    @ 2016-11-15 13:33:28

    #include<iostream>
    #include<algorithm>
    using namespace std;
    int num[101];
    bool flag[101];
    int main()
    {
    int a,result=0;
    cin>>a;
    for(int i=0;i<a;i++)
    cin>>num[i];
    sort(num+0,num+a);
    for(int i=0;i<a-1;i++)
    for(int j=i+1;j<a;j++)
    {
    int temp=num[i]+num[j];
    for(int k=0;k<a;k++)
    if(num[k]==temp&&!flag[k])
    {
    result++;
    flag[k]=true;
    }
    }
    cout<<result;
    return 0;
    }

  • 0
    @ 2016-11-10 18:07:01

    #include <bits/stdc++.h>
    using namespace std;

    int a[1000],n;
    bool b[100000];
    int main()
    {
    cin>>n;
    for (int i=0;i<n;i++)
    cin>>a[i];
    for (int i=0;i<n;i++)
    for (int j=0;j<n;j++)
    if (a[i]!=a[j])
    b[a[i]+a[j]]=true;

    int ans=0;
    for (int i=0;i<n;i++)
    if (b[a[i]])
    ans++;
    cout<<ans<<endl;
    return 0;
    }

  • 0
    @ 2016-09-28 18:37:51

    简单

    #include<iostream>
    using namespace std;
    int main(){
        int n,a[102],ans=0,i,j,k;
        cin>>n;
        for(i=0;i<n;++i){
            cin>>a[i];
        }
        for(i=0;i<n;++i){
            for(j=0;j<n;++j){
                for(k=0;k<n;++k){
                    if(a[i]==a[j]+a[k]&&j!=k){
                        ++i;
                        j=k=0;
                        ++ans;
                    }
                }
            }
        }
        cout<<ans;
        return 0;
    }
    
  • 0
    @ 2016-09-05 11:06:56
    C
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        int n, i;
        scanf("%d",&n);
        int a[100];
        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        int j, k, t, s = 0;
        for(i=0;i<n;i++)
        {
            for(j=0;j<n-1;j++)
            {
                t = 1;
                for(k=j+1;k<n;k++)
                {
                    if(k!=i && j!=i && a[k]+a[j]==a[i])
                    {
                        t=0;
                        break;
                    }
                }
                if(t == 0)
                {
                    s++;
                    break;
                }
            }
        }
        printf("%d",s);
    
        return 0;
    }
    
  • 0
    @ 2016-08-24 13:54:32

    题目有坑,还是个大坑!!!5=2+3和5=1+4是算同一个的!!!!!!!!
    var
    n,i,j,k,ans:longint;
    a,b:array[1..10000] of longint;
    procedure qsort(l,r:longint);
    var
    i,j,mid,p:longint;
    begin
    i:=l;
    j:=r;
    mid:=a[(l+r) div 2];
    repeat
    while a[i]<mid do inc(i);
    while a[j]>mid do dec(j);
    if i<=j then begin
    p:=a[i]; a[i]:=a[j]; a[j]:=p;
    inc(i);
    dec(j);
    end;
    until i>j;
    if l<j then qsort(l,j);
    if i<r then qsort(i,r);
    end;
    begin
    readln(n);
    for i:=1 to n do begin
    read(a[i]);
    end;
    readln;
    qsort(1,n);
    for i:=3 to n do begin
    for j:=1 to i-2 do begin
    for k:=j+1 to i-1 do begin
    if a[j]+a[k]=a[i] then begin
    b[i]:=1;
    end;
    end;
    end;
    end;
    for i:=1 to n do begin
    if b[i]=1 then inc(ans);
    end;
    writeln(ans);
    end.

  • 0
    @ 2016-08-12 21:47:47

    评测结果
    编译成功

    测试数据 #0: Accepted, time = 15 ms, mem = 520 KiB, score = 10
    测试数据 #1: Accepted, time = 15 ms, mem = 516 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 516 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 512 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 512 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 516 KiB, score = 10
    测试数据 #6: Accepted, time = 15 ms, mem = 516 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 516 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 512 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 516 KiB, score = 10
    Accepted, time = 45 ms, mem = 520 KiB, score = 100
    代码
    #include <stdio.h>
    #include <string.h>

    int main()
    {
    int n,mark=0;
    scanf("%d",&n);
    int group[n],max,t;
    for(int p=0;p<n;p++)
    scanf("%d",&group[p]);
    for(max=group[0],t=1;t<n;t++)
    {
    if(group[t]>max)
    max=group[t];
    }

    int box[max];
    memset(box,0,sizeof(int)*max);
    for(int k=0;k<n;k++)
    box[group[k]-1]=1;

    for(int f=0;f<n-1;f++)
    {
    for(int r=f+1;r<n;r++)
    {
    for(int g=0;g<n;g++)
    {
    if((box[group[g]-1]==1) && group[f]+group[r]==group[g])
    {
    mark++;
    box[group[g]-1]=0;
    break;
    }
    }
    }
    }

    printf("%d",mark);
    return 0;
    }

  • 0
    @ 2016-08-12 10:02:51
    评测结果
    编译成功
    
    测试数据 #0: Accepted, time = 0 ms, mem = 524 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 524 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 528 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 528 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 528 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 524 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 524 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 528 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 528 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 524 KiB, score = 10
    Accepted, time = 0 ms, mem = 528 KiB, score = 100
    代码
    #include <bits/stdc++.h>
    bool hash[20001];
    int a[1001],n,ans = 0;
    int main() {
      //freopen("count.in","r",stdin);
      //freopen("count.out","w",stdout);
      scanf("%d",&n);
      memset(hash,false,sizeof(hash));
      for (int i = 1;i <= n;i++)
        scanf("%d",&a[i]);
      for (int i = 1;i <= n;i++)
        for (int j = 1;j <= n;j++) {
          if (i == j) continue;
          hash[a[i]+a[j]] = true;
        }
      for (int i = 1;i <= n;i++)
        if (hash[a[i]]) ans++;
      printf("%d",ans);
      return 0;
    }
    
  • 0
    @ 2016-08-10 17:55:48
    #include <cstdio>
    #include <cstring>
    const int MAXN=20009;
    int main(){
        int a[MAXN],ans=0,n;
        bool vis[MAXN];
        scanf("%d",&n);
        memset(vis,false,sizeof(vis));
        for (int i=1;i<=n;i++){
            scanf("%d",&a[i]);
            for (int j=1;j<=i-1;j++)
                if (a[i]!=a[j]) vis[a[i]+a[j]]=true;
        }
        vis[1]=false;
        for (int i=1;i<=n;i++) if (vis[a[i]]) ans++;
        printf("%d",ans);
        return 0;
    }
    
  • 0
    @ 2016-08-09 17:53:37
    //发现符合条件后即可跳出,进入下一个数。
    代码
    #include<stdio.h>
    int main()
    {
        int n,i,j,k,a[101],re=0;
        scanf("%d",&n);
        for(i=0;i<n;i++)scanf("%d",&a[i]);
        for(i=0;i<n;i++)
        {
          for(j=0;j<n;j++)
              for(k=0;k<n;k++)
                  if(a[i]==a[j]+a[k]&&j!=k){i++;j=0;k=0;re++;}
        }
        printf("%d",re);
        return 0;
    }```
    
  • 0
    @ 2016-08-03 08:47:25

    var
    i,j,k,n,x:longint;
    a:array[0..100] of longint;
    b:array[0..100] of boolean;
    procedure paixu;
    var
    i,j:integer;
    begin

    for i:=1 to n-1 do
    for j:=n downto i+1 do
    if a[j]<a[j-1] then
    begin
    a[0]:=a[j];
    a[j]:=a[j-1];
    a[j-1]:=a[0];
    end;

    end;

    begin
    readln(n);
    for i:=1 to n do

    read(a[i]);
    paixu;
    for i:=1 to n do
    for j:=1 to n do
    for x:=1 to n do
    if (i<j) and (j<x) and (a[i]+a[j]=a[x])
    then
    begin
    b[x]:=true;
    end;
    for i:=1 to 100 do
    if b[i] then k:=k+1;
    writeln(k);
    readln;
    readln;
    end.

  • 0
    @ 2016-07-30 20:40:20

    用map随便搞搞就好了
    ```
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <map>
    using namespace std;

    int cnt=0,N;
    int a[110];
    map<int,bool> m;
    int main(){
    cin>>N;
    for(int i=1;i<=N;++i){
    cin>>a[i];
    }
    for(int i=1;i<=N;++i){
    for(int j=1;j<=N;++j){
    if(i!=j){
    m[a[i]+a[j]]=true;
    }
    }
    }
    for(int i=1;i<=N;++i){
    if(m[a[i]]){
    cnt++;
    }
    }
    cout<<cnt;
    return 0;
    }
    ```

  • 0
    @ 2016-07-26 17:28:30
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #include <cstring>
    #include <queue>
    
    using namespace std;
    
    int n,x,a[20008],ans;
    bool b[30000];
    
    int main()
    {
        //ios::sync_with_stdio(0);
        cin>>n;
        for(int i=1;i<=n;i++)
          {
            cin>>x;
            a[x]++;
          }
        for(int i=1;i<=10000;i++)
         if(a[i])
          for(int j=i+1;j<=10000;j++)
          {
           if(a[j]&& b[i+j]==0 &&a[i+j])
           {
             //cout<<i+j<<endl;
             b[i+j]=1;
             ans++;
           }
           if(i+j>10000) break;
         }
        cout<<ans;
        return 0;
    }
    
  • 0
    @ 2016-07-14 22:58:48

    #include <cstdio>

    int main(){
    // freopen("in.txt","r",stdin);
    int n,a[500],c2[101]={0},count=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    scanf("%d",&a[i]);
    for(int k=1;k<=n;k++)
    for(int i=1;i<=n;i++)
    for(int j=i+1;j<=n;j++)
    if(a[k]==a[i]+a[j]&&k!=i&&k!=j)
    c2[k]++;
    for(int i=1;i<=n;i++)
    if(c2[i]>0)
    count++;
    printf("%d",count);
    return 0;
    }

  • 0
    @ 2016-07-04 15:43:35

    测试数据 #0: Accepted, time = 0 ms, mem = 488 KiB, score = 10
    测试数据 #1: Accepted, time = 15 ms, mem = 488 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 484 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 488 KiB, score = 10
    测试数据 #4: Accepted, time = 15 ms, mem = 488 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 488 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 488 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 488 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 484 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 484 KiB, score = 10
    Accepted, time = 30 ms, mem = 488 KiB, score = 100

    C:

    #include <stdio.h>

    int main() {
    int i, j, k, count=0;
    int n, A[101], b[101];
    scanf("%d", &n);
    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[i] == A[j] + A[k]) {
    b[i] = 1;
    }
    }
    }
    }
    for(i=1; i<=n; i++) {
    if(b[i] == 1) count++;
    }
    printf("%d", count);
    return 0;
    }

  • 0
    @ 2016-06-27 17:27:36
    #include<iostream>
    #include<cstdio>
    using namespace std;
    
    const int maxn = 100 + 5;
    const int maxnum = 100000 + 10;
    int n;
    int ans;
    int maxx;
    int num[maxn];
    bool vis[maxnum];
    bool vis1[maxnum];
    
    int main ()
    {
        //freopen ("in.txt", "r", stdin);
        cin >> n;
        for (int i = 0; i < n; i++) {
            cin >> num[i];
            vis1[num[i]] = true;
            maxx = max (maxx, num[i]);
        }
        for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (i != j && num[i] + num[j] <= maxnum) vis[num[i]+num[j]] = true;
        for (int i = 0; i <= maxx; i++) {
            if (vis[i] && vis1[i]) ans++;
        }
        cout << ans;
        return 0;
    }
    
  • 0
    @ 2016-05-28 21:44:30
    #include<cstdio>
    int hash[10010],a[120],n,ans;
    int main(){
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
            int q=a[i];
            hash[q]=1;
        }
        for(int i=1;i<=n;i++)
            for(int j=1;j<i;j++){
                int q=a[i]+a[j];
                if(hash[q]==1){
                    ans++;
                    hash[q]=0;
                }
            }
        printf("%d\n",ans);
        return 0;
    }
    

    为什么会 runtimeerror??

  • 0
    @ 2016-05-22 14:53:03

    我觉得这道题应该注意的是:“其中有多少个数,恰好等于集合中另外两个(不同的)数之和”, 而不是:“集合中有多少对数的和在集合中”。不认真读题吃亏啊!

  • 0
    @ 2016-05-15 14:33:10

    钙氧氮碘钡钡

  • 0
    @ 2016-05-06 18:22:53

    测试数据 #0: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 560 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 556 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 560 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 560 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 560 KiB, score = 10
    #include<iostream>
    using namespace std;
    int ans;
    int a[101];

    int n;
    bool p[101];
    int main()
    {
    int i,j,k;
    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++)
    if(a[i]>a[j])
    swap(a[i],a[j]);
    for(i=1;i<=n-2;i++)
    for(j=i+1;j<=n-1;j++)
    for(k=j+1;k<=n;k++)
    if(a[i]+a[j]==a[k])
    p[k]=1;
    for(i=1;i<=n;i++)
    if(p[i]==1)
    ans++;
    cout<<ans;
    }

信息

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