zoukankan      html  css  js  c++  java
  • PAT (Advanced Level) 1075 PAT Judge

    题解

              模拟。

              题目有三种状态。

              第一种为题目得到了一定的分数( >= 0);

              第二种为题目提交过但是没有通过编译(代码中状态为 -2 ,输出对应 0 );

              第三种题目根本就没提交过(代码中状态为 -1 ,输出对应 ‘-’ )。

              考生只要至少有一道题目满足第一种情况,即可将这位考生的信息输出出来。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    int N,K,M,score[6];
    struct node
    {
        int name,grade[6],total_solve,sum,rank,isactive;
        node()
        {
            fill(grade,grade+6,-1);
            total_solve=sum=isactive=0;
        }
        void set_grade(int num,int w)
        {
            if(w==score[num]&&grade[num]!=score[num]) total_solve++;
            if(w>=0) isactive=1;
    
            if(w==-1&&grade[num]==-1)   grade[num]=-2;
            else if(grade[num]<w&&w>=0)
            {
                if(grade[num]!=-1&&grade[num]!=-2) sum-=grade[num];
                sum+=w;
                grade[num]=w;
            }
        }
    };
    bool cmp(node x,node y)
    {
      if(x.sum!=y.sum)
            return x.sum>y.sum;
      else
      {
        if(x.total_solve!=y.total_solve)
            return x.total_solve>y.total_solve;
        else
            return x.name<y.name;
      }
    }
    vector<node> v;
    int main() 
    {
        int j,i,id,cnt=1,same,pre_grade=-1,w,name;
        scanf("%d%d%d",&N,&K,&M);
        v.resize(N+1);
    
        for(i=1;i<=K;i++) scanf("%d",&score[i]);
        
        for(i=1;i<=M;i++)
        {
            scanf("%d%d%d",&name,&id,&w);
            v[name].name=name;
            v[name].set_grade(id,w);
        }
    
        sort(v.begin()+1,v.end(),cmp);
        for(i=1;i<=N;i++)
        {
            if(v[i].isactive==0) continue;
            if(v[i].sum!=pre_grade)
            {
                v[i].rank=cnt;
                same=cnt;
                pre_grade=v[i].sum;
            }
            else  v[i].rank=same;
            cnt++;    
        }
    
        for(i=1;i<=N;i++)
        {
            if(v[i].isactive==0) continue;
            printf("%d %05d %d",v[i].rank,v[i].name,v[i].sum);
            for(j=1;j<=K;j++) 
            {
                if(v[i].grade[j]==-1)  printf(" -");
                else  printf(" %d",v[i].grade[j]==-2?0:v[i].grade[j]);
            }
            printf("
    ");
        }
        system("pause");
        return 0;
    }
  • 相关阅读:
    牛顿迭代法 Newton-Raphson Method
    [LeetCode]73. Sqrt(x)平方根
    [LeetCode]72. Basic Calculator基本计算器
    [LeetCode]71. Missing Number缺失的数
    [LeetCode]70. Ugly Number II第N个丑数
    [LeetCode]69. Recerse Integer旋转整数
    [LeetCode]68. Palindrome Number回文数字
    [LeetCode]67. Number of Digit One1的个数和
    [LeetCode]66. Factorial Trailing Zeros阶乘的尾零个数
    STL的容器哈希表
  • 原文地址:https://www.cnblogs.com/VividBinGo/p/12227495.html
Copyright © 2011-2022 走看看