题解

27 条题解

  • 2
    @ 2015-04-23 22:11:42

    #include<iostream>
    #include<cstring>
    using namespace std;
    int a[205],b[205],c[205];
    int booka[101],bookb[101],bookc[101];
    int sc[205];
    int n;
    int main()
    {
    cin>>n;
    for(int i=1;i<=n;i++){cin>>a[i]>>b[i]>>c[i]; booka[a[i]]++;bookb[b[i]]++;bookc[c[i]]++;}
    for(int i=1;i<=n;i++){if(booka[a[i]]==1)sc[i]+=a[i];if(bookb[b[i]]==1)sc[i]+=b[i];
    if(bookc[c[i]]==1)sc[i]+=c[i];}
    for(int i=1;i<=n;i++)cout<<sc[i]<<endl;

    return 0;
    }
    O(n)

  • 1
    @ 2015-10-19 19:10:25

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    struct kid{
    int number[4];
    }a[201];
    int n,sum[201];
    bool check[201],change[201];
    void init()
    {
    int i,j;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
    for(j=1;j<=3;j++){
    scanf("%d",&a[i].number[j]);
    }
    }
    }
    void add(int t)
    {
    int i;
    for(i=1;i<=n;i++){
    if(check[a[i].number[t]]){
    sum[i]+=a[i].number[t];
    }
    }
    }
    void print()
    {
    int i;
    for(i=1;i<=n;i++){
    printf("%d\n",sum[i]);
    }
    }
    void work()
    {
    int i,j;
    for(i=1;i<=3;i++){
    memset(check,false,sizeof(check));
    memset(change,false,sizeof(change));
    for(j=1;j<=n;j++){
    if(!check[a[j].number[i]]&&!change[a[j].number[i]]){
    check[a[j].number[i]]=true;
    }
    else{
    check[a[j].number[i]]=false;
    change[a[j].number[i]]=true;
    }
    }
    add(i);
    }
    print();
    }
    int main()
    {
    init();
    work();
    return 0;

    }

  • 1
    @ 2015-10-07 21:41:24

    #include<iostream>
    #include<cmath>
    #include<cstring>
    #include<cstdio>
    #include<cstdlib>
    #include<algorithm>
    using namespace std;
    int n,m,i,j,s;
    int a[200+5],b[200+5],c[200+5],aa[200+5],bb[200+5],cc[200+5],zongfen[200+5];
    int main()
    {
    scanf("%d",&n);
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    memset(c,0,sizeof(c));
    memset(aa,0,sizeof(aa));
    memset(bb,0,sizeof(bb));
    memset(cc,0,sizeof(cc));
    for(i=1;i<=n;i++)
    scanf("%d %d %d",&a[i],&b[i],&c[i]);
    //cin>>a[i]>>b[i]>>c[i];
    for(i=1;i<=n-1;i++)
    for(j=i+1;j<=n;j++)
    {
    if(a[i]==a[j])
    {
    aa[i]=1;
    aa[j]=1;
    }
    if(b[i]==b[j])
    {
    bb[i]=1;
    bb[j]=1;
    }
    if(c[i]==c[j])
    {
    cc[i]=1;
    cc[j]=1;
    }

    }
    for(i=1;i<=n;i++)
    {
    if(aa[i]==0)
    zongfen[i]+=a[i];
    if(bb[i]==0)
    zongfen[i]+=b[i];
    if(cc[i]==0)
    zongfen[i]+=c[i];
    }
    for(i=1;i<=n;i++)
    printf("%d\n",zongfen[i]);
    return 0;

    }

    • @ 2015-10-07 21:44:13

      恩,很有道理

  • 1
    @ 2015-04-22 17:01:00

    var
    i,n:longint;
    a,b,c,d,e,f,x:array[1..1000]of longint;
    begin
    read(n);
    for i:=1 to n do begin
    read(a[i],b[i],c[i]);
    inc(d[a[i]]);inc(e[b[i]]);inc(f[c[i]]);
    end;
    for i:=1 to n do begin
    if d[a[i]]=1 then x[i]:=x[i]+a[i];
    if e[b[i]]=1 then x[i]:=x[i]+b[i];
    if f[c[i]]=1 then x[i]:=x[i]+c[i];
    end;
    for i:=1 to n do writeln(x[i]);
    end.
    桶排 很麻烦吗

  • 0
    @ 2018-08-20 09:25:45
    /*
    如此水的一道省选题~
    NOIPT1难度吧?
    直接模拟就好了~
    这个代码长度给满分啊
    */
    #include <iostream>
    using namespace std;
    
    const int MAXN=205;
    int p[MAXN>>1][3];
    int a[MAXN][3];
    int ans[MAXN];
    int n;
    
    void init()
    {
        cin>>n;
        for(int i=1;i<=n;i++)
            for(int j=0;j<3;j++)
                cin>>a[i][j];
    }
    
    int main()
    {
        init();
        for(int j=0;j<3;j++)
            for(int i=1;i<=n;i++)
                p[a[i][j]][j]++;
        for(int k=0;k<3;k++)
            for(int i=1;i<=n;i++)
                if(p[a[i][k]][k]==1)
                    ans[i]+=a[i][k];
        for(int i=1;i<=n;i++)
            cout<<ans[i]<<endl;
        return 0;
    }
         
    
  • 0
    @ 2017-09-12 16:58:53

    int main(){
    int N, i, j, t;
    int k[3][200] = { 0 }, s[200] = { 0 };
    scanf_s("%d", &N);
    if (2 <= N && N <= 200){
    for (j = 0; j < N; j++){
    for (i = 0; i < 3; i++){
    scanf_s("%d", &k[i][j]);
    }
    }
    }
    for (i = 0; i < N; i++){
    s[i] = k[0][i] + k[1][i] + k[2][i];
    }
    for (j = 0; j < 3; j++){
    for (i = 1; i < N; i++){
    if (k[j][0] == k[j][i]){
    s[0] = s[0] - k[j][0];
    break;
    }
    }
    }
    for (t = 1; t < N; t++){
    for (j = 0; j < 3; j++){
    for (i = 0; i < N; i++){
    if (t == i){
    break;
    }
    else{
    if (k[j][t] == k[j][i]){
    s[t] = s[t] - k[j][t];
    break;
    }
    }
    }
    }
    }
    for (i = 0; i < N; i++){
    printf("%d\n", s[i]);
    }
    return 0;
    }

  • 0
    @ 2017-05-02 14:08:28

    垃圾题目

    #include<stdio.h>
    #include<set>
    using namespace std;
    multiset<int> s;
    int n,f[1000][4];
    int main(){
        scanf("%d",&n);
        for(int i=0;i<n;++i) scanf("%d%d%d",f[i],f[i]+1,f[i]+2);
        for(int i=0;i<3;++i){
            s.clear();
            for(int j=0;j<n;++j) s.insert(f[j][i]);
            for(int j=0;j<n;++j) if(s.count(f[j][i])<2) f[j][3]+=f[j][i];
        }
        for(int i=0;i<n;++i) printf("%d\n",f[i][3]);
    }
    
  • 0
    @ 2016-12-22 19:51:54

    注意可以200个人玩,把数组开到两百以上就不会RE了,代码供参考。只用了一维数组,没用二维。
    ```c++

    #include<cstdio>
    int main()
    {
    int n;
    int d[205]= {0},e[205]= {0},f[205]= {0},g[205] = {0};
    int a[105] = {0},b[105] = {0},c[105] = {0};
    scanf("%d",&n);
    int i=1;
    while(n--)
    {
    scanf("%d%d%d",&d[i],&e[i],&f[i]);
    if(a[d[i]] == 1 || a[d[i]] == -1)
    a[d[i]] = -1;
    else
    a[d[i]] = 1;

    if(b[e[i]] == 1 || b[e[i]] == -1)
    b[e[i]] = -1;
    else
    b[e[i]] = 1;

    if(c[f[i]] == 1 || c[f[i]] == -1)
    c[f[i]] = -1;
    else
    c[f[i]] = 1;
    i++;
    }

    for(int j=1;j < i;j++)
    {
    if(a[d[j]] == 1) g[j] += d[j];
    if(b[e[j]] == 1) g[j] += e[j];
    if(c[f[j]] == 1) g[j] += f[j];
    printf("%d\n",g[j]);
    }
    return 0;
    }

  • 0
    @ 2016-08-11 14:00:26

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

  • 0
    @ 2016-07-17 15:04:07

    一次AC

    var i,j,n:longint;
        s:array [1..100]of longint;
        a:array[1..200,1..3]of longint;
        b:array[1..200]of longint;
    begin
      readln(n);
      for i:=1 to n do
        readln(a[i,1],a[i,2],a[i,3]);
      fillchar(b,sizeof(b),0);
      for j:=1 to 3 do
        begin
          fillchar(s,sizeof(s),0);
          for i:=1 to n do
            inc(s[a[i,j]]);
          for i:=1 to n do
            if s[a[i,j]]=1 then b[i]:=b[i]+a[i,j];
        end;
      for i:=1 to n do
        writeln(b[i]);
    end.
    
  • 0
    @ 2016-07-01 19:21:38
    using namespace std;
    int main()
    {
        int a[3][205],i,n,j,m=0;
        bool b[3][205];
        cin>>n;
        for(i=0;i<=n-1;i++) 
        {
            b[0][i]=true;
            b[1][i]=true;
            b[2][i]=true;
            cin>>a[0][i]>>a[1][i]>>a[2][i];
        }
        
        for(i=0;i<=n-1;i++) 
            for(j=i+1;j<=n-1;j++){
            
                if(a[0][i]==a[0][j])
                {
                    b[0][i]=false;
                    b[0][j]=false;
                }
                if(a[1][i]==a[1][j])
                {
                    b[1][i]=false;
                    b[1][j]=false;
                }
                if(a[2][i]==a[2][j])
                {
                    b[2][i]=false;
                    b[2][j]=false;
                }}
        for(i=0;i<=n-1;i++){
        
        
        
            for(j=0;j<=2;j++)
                if(b[j][i]==0) a[j][i]=0;
            cout<<a[0][i]+a[1][i]+a[2][i]<<endl;
     }
        return 0;
    }```
    
  • 0
    @ 2016-06-30 18:47:31

    ac

  • 0
    @ 2016-06-06 13:07:58

    不能,

  • 0
    @ 2016-06-06 13:07:49

    不要粘贴复制

  • 0
    @ 2016-06-06 13:07:40

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

  • 0
    @ 2016-06-06 12:54:39

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

  • 0
    @ 2016-05-31 01:44:52

    桶排序思想。时间复杂度O(n);

    include <stdio.h>

    include <stdlib.h>

    define MAX 500

    int a[102], b[102], c[102], sum[205];

    int main (void)
    {
    int n, i, temp1, temp2, temp3;
    scanf("%d",&n);
    for (i=1; i<=n; i++) {
    scanf("%d%d%d",&temp1,&temp2,&temp3);
    if (a[temp1]) {
    if (a[temp1] != MAX) {
    sum[a[temp1]] -= temp1;
    a[temp1] = MAX;
    }
    }
    else {
    a[temp1] = i;
    sum[i] += temp1;
    }
    if (b[temp2]) {
    if (b[temp2] != MAX) {
    sum[b[temp2]] -= temp2;
    b[temp2] = MAX;
    }
    }
    else {
    b[temp2] = i;
    sum[i] += temp2;
    }
    if (c[temp3]) {
    if (c[temp3] != MAX) {
    sum[c[temp3]] -= temp3;
    c[temp3] = MAX;
    }
    }
    else {
    c[temp3] = i;
    sum[i] += temp3;
    }
    }
    for (i=1; i<=n; i++) {
    printf("%d\n",sum[i]);
    }

    return 0;
    }

  • 0
    @ 2016-05-19 13:27:57
    评测结果
    编译成功
    
    测试数据 #0: Accepted, time = 0 ms, mem = 488 KiB, score = 5
    测试数据 #1: Accepted, time = 0 ms, mem = 484 KiB, score = 5
    测试数据 #2: Accepted, time = 0 ms, mem = 488 KiB, score = 5
    测试数据 #3: Accepted, time = 0 ms, mem = 492 KiB, score = 5
    测试数据 #4: Accepted, time = 0 ms, mem = 488 KiB, score = 5
    测试数据 #5: Accepted, time = 0 ms, mem = 488 KiB, score = 5
    测试数据 #6: Accepted, time = 0 ms, mem = 488 KiB, score = 5
    测试数据 #7: Accepted, time = 0 ms, mem = 484 KiB, score = 5
    测试数据 #8: Accepted, time = 0 ms, mem = 484 KiB, score = 5
    测试数据 #9: Accepted, time = 0 ms, mem = 492 KiB, score = 5
    测试数据 #10: Accepted, time = 0 ms, mem = 488 KiB, score = 5
    测试数据 #11: Accepted, time = 0 ms, mem = 488 KiB, score = 5
    测试数据 #12: Accepted, time = 0 ms, mem = 488 KiB, score = 5
    测试数据 #13: Accepted, time = 0 ms, mem = 484 KiB, score = 5
    测试数据 #14: Accepted, time = 0 ms, mem = 488 KiB, score = 5
    测试数据 #15: Accepted, time = 0 ms, mem = 492 KiB, score = 5
    测试数据 #16: Accepted, time = 0 ms, mem = 488 KiB, score = 5
    测试数据 #17: Accepted, time = 0 ms, mem = 484 KiB, score = 5
    测试数据 #18: Accepted, time = 0 ms, mem = 492 KiB, score = 5
    测试数据 #19: Accepted, time = 0 ms, mem = 488 KiB, score = 5
    Accepted, time = 0 ms, mem = 492 KiB, score = 100
    代码
    #include<cstdio>
    using namespace std;
    int main()
    {
      int n,i,j,k;
      scanf("%d",&n);
      int g[201][4],q;
      for(i=1;i<=n;i++)
        for(j=1;j<=3;j++)
          scanf("%d",&g[i][j]);
        for(i=1;i<=n;i++)
        {
          q=0;
          for(j=1;j<=3;j++)
          {
            for(k=1;k<=n;k++)
            {
              if(k==i)continue;
              if(g[i][j]==g[k][j]) //第i个小朋友第j轮给出的数 和 第1~第n个小朋友第j轮给出的数比较
                break; 
            }
            if(k>n) //若都不相同,就累加进去
              q+=g[i][j];
          }
          printf("%d\n",q);
        }
      //system("pause");
      return 0;
    }
    
  • 0
    @ 2015-05-04 21:59:22

    一开始不知道哪里打错了,爆了RE,怒然开到上千,方才AC……
    #include <vector>
    #include <list>
    #include <limits.h>
    #include <set>
    #include <deque>
    #include <queue>
    #include <stack>
    #include <bitset>
    #include <algorithm>
    #include <functional>
    #include <numeric>
    #include <utility>
    #include <sstream>
    #include <iostream>
    #include <iomanip>
    #include <cstdio>
    #include <cmath>
    #include <cstdlib>
    #include <ctime>
    #include <cstring>
    #include <memory.h>
    using namespace std;

    int n,s[1100][40],t[40][1100];

    void init()
    {
    memset(s,0,sizeof(s));
    memset(t,0,sizeof(t));
    scanf("%d",&n);
    for (int i = 1; i <= n; ++ i)
    for (int j = 1; j <= 3; ++ j)
    {
    scanf("%d",&s[i][j]);
    ++ t[j][ s[i][j] ];
    }
    }

    void work()
    {
    int ans;
    for (int i = 1; i <= n; ++ i)
    {
    ans = 0;
    for (int j = 1; j <= 3; ++ j)
    if (t[j][ s[i][j] ] == 1)
    ans += s[i][j];
    printf("%d\n",ans);
    }
    }

    int main()
    {
    init();
    work();
    return 0;
    }

    • @ 2016-12-22 19:50:22

      开到200以上就好。。。因为可以200个人玩。。。所以这里开大点就好了。。。因为我刚刚re几次,突然仔细看题发现了。。。。然后ac

  • 0
    @ 2015-04-21 21:42:49

    因为报数的范围在1~100
    num[-1]表示有超过两个人报这个数
    num[0]表示没人报这个数
    其他的就是对于num[i]的值为报它的人的编号

    #include<stdio.h>
    #include<string.h>
    int num[101],f[201][4],g[201];
    int main()
    {
    int N;
    scanf("%d",&N);
    for(int i=1;i<=N;i++)
    {
    for(int j=1;j<=3;j++)
    {
    scanf("%d",&f[i][j]);
    }
    }
    for(int i=1;i<=3;i++)
    {
    memset(num,0,sizeof(num));
    for(int j=1;j<=N;j++)
    {
    if(num[f[j][i]]==-1)
    {
    continue;
    }else if(num[f[j][i]])
    {
    num[f[j][i]]=-1;
    }else
    {
    num[f[j][i]]=j;
    }
    }
    for(int j=1;j<=100;j++)
    {
    if(num[j]!=0&&num[j]!=-1)
    {
    g[num[j]]+=f[num[j]][i];
    }
    }

    }
    for(int i=1;i<=N;i++)
    {
    printf("%d\n",g[i]);
    }
    return 0;

    }

信息

ID
1941
难度
3
分类
(无)
标签
递交数
854
已通过
455
通过率
53%
上传者