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("\n");
    }
    system("pause");
    return 0;
}

原文地址:https://www.cnblogs.com/VividBinGo/p/12227495.html

时间: 2024-11-07 06:57:58

PAT (Advanced Level) 1075 PAT Judge的相关文章

PAT (Advanced Level) 1075. PAT Judge (25)

简单模拟题. 注意一点:如果一个人所有提交的代码都没编译通过,那么这个人不计排名. 如果一个人提交过的代码中有编译不通过的,也有通过的,那么那份编译不通过的记为0分. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<str

PAT (Advanced Level) 1025. PAT Ranking (25)

简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<queue> #include<string> #include<vector> using namespace std; const int maxn=110; int n,tot=0; int sz[m

PAT (Advanced Level) 1025 PAT Ranking

题解 模拟水题. 代码 #include<bits/stdc++.h> using namespace std; struct node { string name; int final_rank,loc_num,loc_rank,grade; node(string name,int loc_num,int grade) { this->name=name; this->loc_num=loc_num; this->grade=grade; } void paixu(int

Pat(Advanced Level)Practice--1018(Public Bike Management)

Pat1018代码 题目描述: There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any station and return it to any other stations in the city. The Public Bike Management C

Pat(Advanced Level)Practice--1043(Is It a Binary Search Tree)

Pat1043代码 题目描述: A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node contains only nodes

Pat(Advanced Level)Practice--1044(Shopping in Mars)

Pat1044代码 题目描述: Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can be cut at any position for only once and some of the diam

PAT (Advanced Level) 1093. Count PAT&#39;s (25)

预处理每个位置之前有多少个P,每个位置之后有多少个T. 对于每个A,贡献的答案是这个A之前的P个数*这个A之后T个数. #include<cstdio> #include<cstring> long long MOD=1e9+7; const int maxn=1e5+10; long long dp1[maxn],dp2[maxn]; char s[maxn]; int main() { scanf("%s",s); memset(dp1,0,sizeof d

PAT (Advanced Level) 1055. The World&#39;s Richest (25)

排序.随便加点优化就能过. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<map> #include<queue> #include<string> #include<stack> #include<vector> using names

Pat(Advanced Level)Practice--1076(Forwards on Weibo)

Pat1076代码 题目描述: Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is formed with followers relations. When a user makes a post on Weibo, all hi