浙大PAT 1012题 1012. The Best Rank
来源:互联网 发布:js获取上下文 编辑:程序博客网 时间:2024/05/20 05:26
时间复杂度O(n^2),当n=2000时,复杂度为400 0000,本以为过不了。
但别人写的代码蛮简单的,400ms的时限,100ms能过。
#include <stdio.h>#include <string.h>#define MAX_NUM 0x7ffffffftypedef struct Node{ char ID[10]; int score[4]; int best_rank; int best_course;}Stu;Stu stu[2005];int N,M;char map[]={'C','M','E','A'};int main(){ int i,j,k; scanf("%d %d",&N,&M); for(i=0;i<N;i++){ scanf("%s %d %d %d",&stu[i].ID,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]); stu[i].score[3]=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3; } for(i=0;i<N;i++){ int rank[4]={1,1,1,1}; for(j=0;j<N;j++){ for(k=0;k<4;k++){ if(i!=j&&stu[j].score[k]>stu[i].score[k]) rank[k]++; } } int best_rank=MAX_NUM; int best_course=MAX_NUM; for(j=0;j<4;j++){ if(rank[j]<best_rank){ best_rank=rank[j]; best_course=j; } else if(rank[j]==best_rank){ if(j==3||j<best_course){ best_course=j; } } } stu[i].best_rank=best_rank; stu[i].best_course=best_course; } for(i=0;i<M;i++){ char search[10]; scanf("%s",&search); for(j=0;j<N;j++){ if(strcmp(stu[j].ID,search)==0){ printf("%d %c\n",stu[j].best_rank,map[stu[j].best_course]); break; } } if(j==N) printf("N/A\n"); } return 0; }
- 浙大PAT 1012题 1012. The Best Rank
- 浙大 PAT Advanced level 1012. The Best Rank
- 浙大PAT (Advanced Level) Practise 1012 The Best Rank (25)
- PAT 1012. The Best Rank
- PAT 1012. The Best Rank
- 【PAT】1012. The Best Rank
- pat 1012 The Best Rank
- pat 1012 The Best Rank
- PAT 1012 The Best Rank
- PAT 1012 The Best Rank
- 1012. The Best Rank (25)-PAT甲级真题
- PAT甲级真题1012. The Best Rank (25)
- 1012. The Best Rank (25)-PAT
- pat 1012. The Best Rank (25)
- 【PAT】1012. The Best Rank (25)
- PAT (Advanced) 1012. The Best Rank (25)
- PAT 1012. The Best Rank (25)
- PAT A 1012. The Best Rank (25)
- Ext.grid.CheckColumn
- 自定义Button形状(圆形、椭圆)
- 浙大PAT 1011题 1011. World Cup Betting
- 81
- 一个绚丽的js插件——实现弹出框效果
- 浙大PAT 1012题 1012. The Best Rank
- 链表
- 找出文本中存在的坏单词-后缀trie
- 浙大PAT 1013题 1013. Battle Over Cities
- android SQLite使用
- web前端之javascript
- 浙大PAT 1019题 1019. General Palindromic Number
- 计算网络知识点
- 浙大PAT 1025题 1025. PAT Ranking