标签:style blog http color io os ar for art
1 //Accepted 100 KB 92 ms 2 //模拟 3 #include <cstdio> 4 #include <cstring> 5 #include <iostream> 6 #include <queue> 7 #include <cmath> 8 #include <algorithm> 9 using namespace std; 10 /** 11 * This is a documentation comment block 12 * 如果有一天你坚持不下去了,就想想你为什么走到这儿! 13 * @authr songt 14 */ 15 const int imax_n = 1005; 16 char s[imax_n][35]; 17 int cnts; 18 int a[imax_n]; 19 int b[imax_n]; 20 int n; 21 int search(char name[]) 22 { 23 for (int i=0;i<cnts;i++) 24 { 25 if (strcmp(s[i],name)==0) 26 return i; 27 } 28 return -1; 29 } 30 char sname[imax_n][35]; 31 int score[imax_n]; 32 void slove() 33 { 34 cnts=0; 35 memset(a,0,sizeof(a)); 36 memset(b,0,sizeof(b)); 37 for (int i=0;i<n;i++) 38 { 39 scanf("%s%d",sname[i],&score[i]); 40 int t=search(sname[i]); 41 if (t==-1) 42 { 43 strcpy(s[cnts],sname[i]); 44 a[cnts++]=score[i]; 45 } 46 else 47 { 48 a[t]+=score[i]; 49 } 50 } 51 int ans=-100000000; 52 int tid; 53 for (int i=0;i<cnts;i++) 54 { 55 if (ans<a[i]) 56 { 57 ans=a[i]; 58 } 59 } 60 cnts=0; 61 for (int i=0;i<n;i++) 62 { 63 int t=search(sname[i]); 64 if (t==-1) 65 { 66 strcpy(s[cnts],sname[i]); 67 b[cnts++]=score[i]; 68 if (a[cnts-1]>=ans && score[i]>=ans) 69 { 70 tid=i; 71 break; 72 } 73 } 74 else 75 { 76 b[t]+=score[i]; 77 if (a[t]>=ans && b[t]>=ans) 78 { 79 tid=i; 80 break; 81 } 82 } 83 } 84 printf("%s\n",sname[tid]); 85 } 86 int main() 87 { 88 while (scanf("%d",&n)!=EOF) 89 slove(); 90 return 0; 91 }
1 //Accepted 200 KB 92 ms 2 //模拟 3 //找到总分最大的 4 //若有多个总分最大的m,则找的第一个总分不少于m的总分最大的人 5 #include <cstdio> 6 #include <cstring> 7 #include <iostream> 8 #include <queue> 9 #include <cmath> 10 #include <map> 11 #include <algorithm> 12 using namespace std; 13 /** 14 * This is a documentation comment block 15 * 如果有一天你坚持不下去了,就想想你为什么走到这儿! 16 * @authr songt 17 */ 18 map<string ,int > f,g; 19 const int imax_n = 1005; 20 string s[imax_n]; 21 int score[imax_n]; 22 int n; 23 void slove() 24 { 25 cin>>n; 26 int ans=-10000; 27 for (int i=0;i<n;i++) 28 { 29 cin>>s[i]>>score[i]; 30 f[s[i]]+=score[i]; 31 } 32 for (int i=0;i<n;i++) 33 { 34 if (f[s[i]]>ans) 35 ans=f[s[i]]; 36 } 37 38 //cout<<"ans="<<ans<<endl; 39 int i; 40 for (i=0;i<n;i++) 41 { 42 g[s[i]]+=score[i]; 43 if (f[s[i]]>=ans && g[s[i]]>=ans) break; 44 //cout<<"g[s[i]]="<<g[s[i]]<<endl; 45 } 46 //cout<<"i="<<i<<endl; 47 cout<<s[i]<<endl; 48 } 49 int main() 50 { 51 slove(); 52 return 0; 53 }
标签:style blog http color io os ar for art
原文地址:http://www.cnblogs.com/djingjing/p/3970422.html