PAT鐢茬骇 1075 PAT Judge (25鍒?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT鐢茬骇 1075 PAT Judge (25鍒?相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/str' title='str'>str   def   std   eof   algorithm   printf   long   瑙e喅   using   

//娉ㄦ剰锛氭帓搴忕殑鏄弧鍒嗚В棰樻暟锛岃€屼笉鏄В棰樻暟銆?br />#include <cstdio>
#include <cstring> #include <iostream> #include <algorithm> using namespace std; const int maxn = 200005; typedef long long ll; struct st{ int num,k[6],total_grade,total_q,order,t;//t浠h〃瑙e喅棰樻暟锛宼otal_q浠h〃瀹岀編瑙i鏁?/span> }s[100005]; bool cmp(st p,st q) {//鎺掑簭 if(p.total_grade != q.total_grade) return p.total_grade > q.total_grade; else if(p.total_q != q.total_q) return p.total_q > q.total_q; else return p.num < q.num; } int main() { int n,k,kk[6],m; scanf("%d%d%d",&n,&k,&m); for(int i = 1; i <= k; i++) scanf("%d",&kk[i]);//姣忕婊″垎 int sno,num,grade; for(int i = 1; i <= n; i++) { s[i].num = i; s[i].total_grade = 0; s[i].total_q = 0; s[i].t = -1; memset(s[i].k,-1,sizeof(s[i].k)); } for(int i = 1; i <= m; i++) { scanf("%d%d%d",&sno,&num,&grade); if(grade >=0 ) { s[sno].t = 1; } else grade = 0; s[sno].k[num] = max(s[sno].k[num],grade); } for(int i = 1; i <= n; i++) { for(int j = 1; j <= k; j++) { if(s[i].k[j] != -1) s[i].total_grade += s[i].k[j]; if(s[i].k[j] ==kk[j]) s[i].total_q++; } } sort(s+1,s+1+n,cmp); for(int i = 1; i <= n; i++) { if(s[i].total_grade == s[i-1].total_grade) s[i].order = s[i-1].order; else s[i].order = i; } /*for(int i = 1; i <= n; i++) printf("%d ",s[i].t); printf(" ");*/ for(int i = 1; i <= n; i++) { if(s[i].t == 1) { printf("%d %05d %d",s[i].order,s[i].num,s[i].total_grade); for(int j = 1; j <= k; j++) { if(s[i].k[j] == -1) printf(" -"); else printf(" %d",s[i].k[j]); } printf(" "); } } return 0; }

 

以上是关于PAT鐢茬骇 1075 PAT Judge (25鍒?的主要内容,如果未能解决你的问题,请参考以下文章

PAT(A) 1075. PAT Judge (25)

1075. PAT Judge (25)

1075. PAT Judge (25)

PATA1075 PAT Judge (25 分)

PAT甲题题解-1075. PAT Judge (25)-排序

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