小明的调查统计(二)
3 410 23 56 89 41 23 54 65 23 89 683 89 78 855 56 68 76 56 741234
1 31 92 12 32 23 3
这一题不是很水!思路要清晰,国庆回来第二水!已加标注!给大家解释一下!请把注释的代码去掉,否则会超时!超时!超时!超时!
平板视图打印?01#include <iostream>02#include <algorithm>03using namespace std;04struct data//data保存输入数据用05{06int number;//人数07int *p;//学生成绩08};09struct one10{11int c;//班级12int zb;//学号13int z;//成绩14int w;//名次15};16//自定义sort排序,先按分数从大到小,再按班级从小到大,再按学号从小到大17bool cmp(one a,one b)18{19if(a.z!=b.z)return a.z>b.z;20if(a.c!=b.c)return a.c<b.c;21return a.zb<b.zb;22}23int main()24{25data *s;one x[100010];26int t,m,i,j,k=0;cin>>t>>m;27s=new data[t];28for(i=0;i<t;i++)//输入数据29{30cin>>s[i].number;31s[i].p=new int[s[i].number];32for(j=0;j<s[i].number;j++) {cin>>s[i].p[j];x[k].zb=j+1;x[k].z=s[i].p[j];x[k].c=i+1;k++;}33}34sort(x,x+k,cmp);35int count=1,h=x[0].z,temp;36for(i=0;i<k;i++)//循环,排序分数名次37{38if(x[i].z!=h) {h=x[i].z;count++;}x[i].w=count;39}40while(m--)41{42cin>>temp;43for(i=0;i<k;i++)44{45if(temp==x[i].w) cout<<x[i].c<<" "<<x[i].zb<<endl;46if(x[i].w>temp) break;47}48}49delete[] s;50return 0;51}原创文章,转载请注明: 转载自ACM解题报告
本文链接地址: 小明的调查统计(二)
This entry was posted in acm水题 and tagged Water by admin. Bookmark the permalink.