题解

173 条题解

  • 0
    @ 2016-04-23 15:16:31
    #include <stdio.h>
    int main()
    {
        int n;
        int a[101];
        int i,j,k;
        int times=0;
        int m,tmp;
        
        scanf("%d",&n);
        m = n;
        j=0;
        for (i=1; i<=n; i++) {
            scanf("%d",&tmp);
            if (tmp<=10000) {
                j++;
                a[j]=tmp;
            }
        }
        n=j;
        for (i=1;i<n;i++)
            for (j=n; j>i; j--) {
                if ((a[i]==a[j])&&(j<=m)) {
                    a[j]=a[m];
                    m--;
                }
            }
    
    
        for (i=1; i<m-1; i++) {
            for (j=i+1; j<m; j++) {
                for (k=j+1; k<=m; k++) {
                    if ((a[i]+a[j]==a[k])||(a[j]+a[k]==a[i])||(a[i]+a[k]==a[j])) {
                        times+=1;
                    }
                }
            }
        }
        printf("%d\n",times);
        
    }
    

    我认为这题答案其实存在错误,根据大家给的答案,这题正确答案把0+a=a的情况算入了结果中。

  • 0
    @ 2016-04-08 22:08:19

    求大神指点错误!

    #include "stdafx.h"
    #include<iostream>
    #include<string.h>
    using namespace std;
    bool check[10000];
    bool checkn[20000];
    int ele[100];
    int sum[100];
    int main()
    {
    memset(checkn, false, sizeof(checkn));
    int n, p = 0;
    cin >> n;
    for (int t = 0; t < n; t++)
    {
    cin >> ele[t];
    check[ele[t]] = true;
    }
    for (int i = 0; i < n; i++)
    {
    for (int j = i + 1; j < n; j++)
    {
    if (check[ele[i] + ele[j]])
    {
    sum[p] = ele[i] + ele[j];
    p++;
    }
    }
    }
    int count = 0;
    for (int i = 0; i < p; i++)
    {
    if (checkn[sum[i]] == false)
    count++;
    checkn[sum[i]] = true;
    }
    cout << count << endl;
    return 0;
    }

  • 0
    @ 2016-03-22 07:42:30

    #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
    @ 2016-03-21 17:05:00

    编译成功

    测试数据 #0: Accepted, time = 15 ms, mem = 2512 KiB, score = 10

    测试数据 #1: Accepted, time = 0 ms, mem = 2512 KiB, score = 10

    测试数据 #2: Accepted, time = 0 ms, mem = 2512 KiB, score = 10

    测试数据 #3: Accepted, time = 0 ms, mem = 2508 KiB, score = 10

    测试数据 #4: Accepted, time = 15 ms, mem = 2508 KiB, score = 10

    测试数据 #5: Accepted, time = 0 ms, mem = 2512 KiB, score = 10

    测试数据 #6: Accepted, time = 0 ms, mem = 2508 KiB, score = 10

    测试数据 #7: Accepted, time = 0 ms, mem = 2508 KiB, score = 10

    测试数据 #8: Accepted, time = 15 ms, mem = 2508 KiB, score = 10

    测试数据 #9: Accepted, time = 0 ms, mem = 2508 KiB, score = 10

    Accepted, time = 45 ms, mem = 2512 KiB, score = 100

    代码
    #include <iostream>
    #include <string.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <algorithm>
    #include <math.h>

    using namespace std;
    bool check[1000005],doublecheck[1000005];
    int num[105];
    int n;
    int main(){
    int ans = 0;
    memset(check,0,sizeof(check));
    memset(doublecheck,0,sizeof(doublecheck));
    scanf("%d",&n);
    for(int i = 1;i <= n;i ++){
    scanf("%d",&num[i]);
    check[num[i]] = true;
    }
    for(int i = 1;i <= n;i ++){
    for(int j = i + 1;j <= n;j ++){
    if(num[i] != num[j]){
    int tmp = num[i] + num[j];
    if(check[tmp] && !doublecheck[tmp]){
    ans ++; doublecheck[tmp] = 1;
    }
    }
    }
    }
    printf("%d\n",ans);
    return 0;
    }

  • 0
    @ 2016-03-21 07:53:52

    代码乌拉拉QWQ
    #include <iostream>
    #include <string.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <algorithm>
    #include <math.h>

    using namespace std;
    bool check[1000005],doublecheck[1000005];
    int num[105];
    int n;
    int main(){
    int ans = 0;
    memset(check,0,sizeof(check));
    memset(doublecheck,0,sizeof(doublecheck));
    scanf("%d",&n);
    for(int i = 1;i <= n;i ++){
    scanf("%d",&num[i]);
    check[num[i]] = true;
    }
    for(int i = 1;i <= n;i ++){
    for(int j = i + 1;j <= n;j ++){
    if(num[i] != num[j]){
    int tmp = num[i] + num[j];
    if(check[tmp] && !doublecheck[tmp]){
    ans ++; doublecheck[tmp] = 1;
    }
    }
    }
    }
    printf("%d\n",ans);
    return 0;
    }

  • 0
    @ 2016-03-09 15:51:19

    ..........数据范围好像有问题。。。。。。。。。丫的。。。交了好几次才发现原来是因为数组开小了= =说好的 10000呢
    #include <iostream>
    #include <string.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <algorithm>
    #include <math.h>

    using namespace std;
    bool check[1000005],doublecheck[1000005];
    int num[105];
    int n;
    int main(){
    int ans = 0;
    memset(check,0,sizeof(check));
    memset(doublecheck,0,sizeof(doublecheck));
    scanf("%d",&n);
    for(int i = 1;i <= n;i ++){
    scanf("%d",&num[i]);
    check[num[i]] = true;
    }
    for(int i = 1;i <= n;i ++){
    for(int j = i + 1;j <= n;j ++){
    if(num[i] != num[j]){
    int tmp = num[i] + num[j];
    if(check[tmp] && !doublecheck[tmp]){
    ans ++; doublecheck[tmp] = 1;
    }
    }
    }
    }
    printf("%d\n",ans);
    return 0;
    }

  • 0
    @ 2016-03-04 21:28:43

    ···pascal
    program sy;
    var n,i,j,k,count,t:longint;
    a:array[1..100]of longint;
    s:array[1..100]of boolean;
    begin
    //fillchar(s,sizeof(s),false);
    count:=0;
    read(n);
    for i:=1 to n do
    begin
    read(a[i]);
    s[i]:=false;
    end;
    for i:=1 to n-1 do
    for j:=i+1 to n do
    begin
    t:=a[i]+a[j];
    for k:=1 to n do
    if (a[k]=t)and(s[k]=false) then
    begin
    inc(count);
    s[k]:=true;
    break;
    end;
    end;
    writeln(count);
    end.
    ···

  • 0
    @ 2016-02-26 18:45:52

    program sy;
    var n,i,j,k,count,t:longint;
    a:array[1..100]of longint;
    s:array[1..100]of boolean;

    begin
    //fillchar(s,sizeof(s),false);

    count:=0;
    read(n);
    for i:=1 to n do
    begin
    read(a[i]);
    s[i]:=false;
    end;
    for i:=1 to n-1 do
    for j:=i+1 to n do
    begin
    t:=a[i]+a[j];
    for k:=1 to n do
    if (a[k]=t)and(s[k]=false) then
    begin
    inc(count);
    s[k]:=true;
    break;
    end;
    end;

    writeln(count);
    end.

  • 0
    @ 2016-02-19 08:32:11

    这道题要注意可能存在数据重复的情况,这种情况只能计算一次……
    c
    #include <stdio.h>
    int n,num[110],have[100000000] = { 0 },ans = 0,cal[10000000] = { 0 };
    int main(){
    int i,j;
    scanf("%d",&n);
    for(i = 1;i<=n;i++){
    scanf("%d",&num[i]);
    have[num[i]] = 1;
    }
    for(i = 1;i<n;i++)
    for(j = i+1;j<=n;j++)
    if(have[num[i]+num[j]]&&!cal[num[i]+num[j]]){
    ans++;cal[num[i]+num[j]] = 1;
    }
    printf("%d\n",ans);
    return 0;
    }

  • 0
    @ 2016-02-18 20:35:54
    #include<iostream>
    #include<string.h>
    using namespace std;
    bool check[10001];
    int a[101];
    int main()
    {
        int i, j, n, x, t = 0;
        memset(check,false,sizeof(check));
        cin>>n;
        for (i = 0; i<n; i++)
        {
            cin>>x;
            check[x] = true;
            a[i] = x;
        }
        for (i = 0; i<n; i++)
        {
            for (j = 0; j<n; j++)
            {
                if (i!=j)
                    if ((a[i] - a[j] > 0) && (a[i] - a[j] != a[j]) && (check[a[i] - a[j]]))
                    {
                        t++;
                        break;                  
                    }
            }
        }
        cout<<t;
        return 0;
    }
    
  • 0
    @ 2016-02-18 20:35:08

    #include<iostream>
    #include<string.h>
    using namespace std;
    bool check[10001];
    int a[101];
    int main()
    {
    int i, j, n, x, t = 0;
    memset(check,false,sizeof(check));
    cin>>n;
    for (i = 0; i<n; i++)
    {
    cin>>x;
    check[x] = true;
    a[i] = x;
    }
    for (i = 0; i<n; i++)
    {
    for (j = 0; j<n; j++)
    {
    if (i!=j)
    if ((a[i] - a[j] > 0) && (a[i] - a[j] != a[j]) && (check[a[i] - a[j]]))
    {
    t++;
    break;

    }
    }
    }
    cout<<t;
    return 0;
    }

  • 0
    @ 2016-02-18 11:33:30
    /* ***********************************************
    Author        :guanjun
    Created Time  :2016/2/18 11:17:11
    File Name     :vijosp1911.cpp
    ************************************************ */
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <stdio.h>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <iomanip>
    #include <list>
    #include <deque>
    #include <stack>
    #define ull unsigned long long
    #define ll long long
    #define mod 90001
    #define INF 0x3f3f3f3f
    #define maxn 10000+10
    #define cle(a) memset(a,0,sizeof(a))
    const ull inf = 1LL << 61;
    const double eps=1e-5;
    using namespace std;
    
    bool cmp(int a,int b){
        return a>b;
    }
    int n;
    int a[110];
    int main()
    {
        #ifndef ONLINE_JUDGE
        //freopen("in.txt","r",stdin);
        #endif
        //freopen("out.txt","w",stdout);
        while(cin>>n){
            map<int,int>mp;
            map<int,int>mp2;
            for(int i=1;i<=n;i++){
                scanf("%d",&a[i]);
                mp[a[i]]=1;
            }
            sort(a+1,a+1+n);
            int ans=0;
            for(int i=1;i<=n;i++){
                for(int j=i+1;j<=n;j++){
                    int x=a[i]+a[j];
                    if(mp[x]&&!mp2[x])ans++,mp2[x]=1;
                }
            }
            printf("%d\n",ans);
        }
        return 0;
    }
    
    
  • 0
    @ 2015-12-10 11:28:39

    真想回到普及组
    program p1911;
    var a,b:array[1..1000]of integer;
    i,j,k,n:integer;
    begin
    readln(n);
    for i:=1 to n do read(a[i]);
    for i:=1 to n do
    for j:=1 to n do
    for k:=j+1 to n do
    if a[i]=a[j]+a[k] then b[i]:=1;
    k:=0;
    for i:=1 to n do
    if b[i]=1 then k:=k+1;
    writeln(k);
    end.

  • 0
    @ 2015-12-02 16:33:19

    program p1975;
    var a:array[0..105,0..105] of char;
    n,m,i,j,sum:longint;
    begin
    readln(n,m);
    for i:=1 to n do
    begin
    for j:=1 to m do
    read(a[i,j]);
    readln;
    end;
    for i:=1 to n do
    begin
    for j:=1 to m do
    if a[i,j]='*' then write('*')
    else
    begin
    sum:=0;
    if a[i-1,j-1]='*' then inc(sum);
    if a[i,j-1]='*' then inc(sum);
    if a[i+1,j-1]='*' then inc(sum);
    if a[i-1,j+1]='*' then inc(sum);
    if a[i-1,j]='*' then inc(sum);
    if a[i+1,j]='*' then inc(sum);
    if a[i,j+1]='*' then inc(sum);
    if a[i+1,j+1]='*' then inc(sum);
    write(sum);
    end;
    writeln;
    end;
    end.

  • 0
    @ 2015-11-04 23:32:39

    1+4=5和2+3=5算一种,我被坑了,一开始全不过

  • 0
    @ 2015-11-04 23:31:50

    #include<iostream>
    #include<math.h>
    #include<fstream>
    using namespace std;
    //ifstream in("count.in");
    //ofstream out("count.out");
    long int n,a[101];
    int flag[101];
    void read()
    {
    int i;
    cin>>n;
    for(i=1;i<=n;i++)
    cin>>a[i];
    }
    void paixu()
    {
    int i,j;
    for(i=1;i<=n-1;i++)
    for(j=i+1;j<=n;j++)
    if(a[i]>a[j])
    swap(a[i],a[j]);
    }
    int work()
    {
    int i,j,k,ans=0;
    for(i=3;i<=n;i++)
    {
    for(j=1;j<=i-2;j++)
    {
    for(k=j+1;k<=i-1;k++)
    if(a[j]+a[k]==a[i]&&flag[i]==1)
    {
    flag[i]=0;
    ans++;
    }
    }
    }
    return ans;
    }
    int main()
    {
    read();
    paixu();
    int i;
    for(i=1;i<=n;i++)
    flag[i]=1;
    cout<<work()<<endl;
    //in.close();
    //out.close();
    return 0;
    }

    正解

  • 0
    @ 2015-11-04 20:53:46

    #include<iostream>
    #include<cstdlib>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<cmath>
    using namespace std;
    int used[100],a[100];
    int i,n,m,j,k;
    int main()
    {
    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(int o=1;o<=n;o++)
    {
    if(a[i]+a[j]==a[o]&&i!=j&&used[o]==0)
    {
    k++;
    used[o]=1;
    }
    }
    printf("%d\n",k);
    return 0;
    }
    这道题要注意条件。是这样的数有几个而不是情况,比如1 2 3 4 5,,1+4=5,2+3=5,但这仅仅是一个数(5),当初没注意这一点,与一等奖交臂失之。。。

  • 0
    @ 2015-10-27 20:06:28

    var
    i,n,j,k,s:longint;
    a:array[1..10000]of longint;
    begin
    readln(n);
    for i:=1 to n do
    read(a[i]);
    for i:=1 to n do
    for j:=1 to i-1 do
    for k:=1 to n do
    if i+j=k then
    inc(s);
    writeln(s);
    end.

  • 0
    @ 2015-10-25 15:37:36

    program eee;
    var a,b:array[1..1000]of integer;
    i,j,k,n:integer;
    begin
    readln(n);
    fillchar(b,sizeof(b),0);
    for i:=1 to n do read(a[i]);
    for i:=1 to n do
    for j:=1 to n do
    for k:=j+1 to n do
    if a[i]=a[j]+a[k] then b[i]:=1;
    k:=0;
    for i:=1 to n do
    if b[i]=1 then k:=k+1;
    writeln(k);
    end.

  • 0
    @ 2015-10-23 09:13:39

    Program P1911;

    type gun=array [0..20000] of longint;

    var n,i,j,k,len,sum:longint; a,b:gun;

    function check(s,ls:longint;sb:gun):boolean;
    var i:longint;
    begin
    if len=0 then exit(false);
    for i:=1 to ls do
    if sb[i]=s then exit(true);
    exit(false);
    end;

    begin
    readln(n);
    for i:=1 to n do read(a[i]);
    len:=0;
    for i:=1 to n do
    for j:=i+1 to n do begin
    k:=a[i]+a[j];
    if not(check(k,len,b)) then begin

    {在b数组的1到len中找是否有k这个数(有:true;没有:False)}
    inc(len);b[len]:=k; end;
    end;
    sum:=0;
    for i:=1 to len do
    if check(b[i],n,a) then inc(sum);
    writeln(sum);
    end.

信息

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