排序。随便加点优化就能过。

  1. #include<iostream>
  2. #include<cstring>
  3. #include<cmath>
  4. #include<algorithm>
  5. #include<cstdio>
  6. #include<map>
  7. #include<queue>
  8. #include<string>
  9. #include<stack>
  10. #include<vector>
  11. using namespace std;
  12.  
  13. struct X
  14. {
  15. char name[];
  16. int age;
  17. int val;
  18. }s[+];
  19. int n,k,cnt;
  20. int ans[+];
  21.  
  22. bool cmp(const int &a,const int &b)
  23. {
  24. if(s[a].val==s[b].val&&s[a].age==s[b].age)
  25. return strcmp(s[a].name,s[b].name)<;
  26. if(s[a].val==s[b].val) return s[a].age<s[b].age;
  27. return s[a].val>s[b].val;
  28. }
  29.  
  30. bool CMP(const X&a,const X&b)
  31. {
  32. if(a.val==b.val&&a.age==b.age)
  33. return strcmp(a.name,b.name)<;
  34. if(a.val==b.val) return a.age<b.age;
  35. return a.val>b.val;
  36. }
  37.  
  38. int main()
  39. {
  40. scanf("%d%d",&n,&k);
  41. for(int i=;i<=n;i++)
  42. scanf("%s%d%d",s[i].name,&s[i].age,&s[i].val);
  43. sort(s+,s++n,CMP);
  44. for(int i=;i<=k;i++)
  45. {
  46. int a,b,c; scanf("%d%d%d",&a,&b,&c);
  47. cnt=;
  48. for(int j=;j<=n;j++){
  49. if(s[j].age>=b&&s[j].age<=c) ans[cnt++]=j;
  50. if(cnt==a) break;
  51. }
  52. printf("Case #%d:\n",i);
  53. if(cnt==) printf("None\n");
  54. else
  55. {
  56. sort(ans,ans+cnt,cmp);
  57. for(int j=;j<min(a,cnt);j++)
  58. printf("%s %d %d\n",s[ans[j]].name,s[ans[j]].age,s[ans[j]].val);
  59. }
  60. }
  61. return ;
  62. }

PAT (Advanced Level) 1055. The World's Richest (25)的更多相关文章

  1. PAT(Advanced Level)1055.The World's Richest

    Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...

  2. PAT (Advanced Level) Practise - 1094. The Largest Generation (25)

    http://www.patest.cn/contests/pat-a-practise/1094 A family hierarchy is usually presented by a pedig ...

  3. PAT (Advanced Level) 1102. Invert a Binary Tree (25)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  4. PAT (Advanced Level) 1098. Insertion or Heap Sort (25)

    简单题.判断一下是插排还是堆排. #include<cstdio> #include<cstring> #include<cmath> #include<ve ...

  5. PAT (Advanced Level) 1067. Sort with Swap(0,*) (25)

    只对没有归位的数进行交换. 分两种情况: 如果0在最前面,那么随便拿一个没有归位的数和0交换位置. 如果0不在最前面,那么必然可以归位一个数字,将那个数字归位. 这样模拟一下即可. #include& ...

  6. PAT (Advanced Level) 1066. Root of AVL Tree (25)

    AVL树的旋转.居然1A了.... 了解旋转方式之后,数据较小可以当做模拟写. #include<cstdio> #include<cstring> #include<c ...

  7. PAT (Advanced Level) 1047. Student List for Course (25)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

  8. PAT (Advanced Level) 1082. Read Number in Chinese (25)

    模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  9. PAT (Advanced Level) 1002. A+B for Polynomials (25)

    为0的不要输出. #include<iostream> #include<cstring> #include<cmath> #include<algorith ...

随机推荐

  1. Linux下将Mysql和Apache加入到系统服务里的方法

    Apache加入到系统服务里面: cp /安装目录下/apache/bin/apachectl /etc/rc.d/init.d/httpd 修改httpd 在文件头部加入如下内容: ### # Co ...

  2. js算数方法

    原文:http://www.w3school.com.cn/js/js_obj_math.asp 除了可被 Math 对象访问的算数值以外,还有几个函数(方法)可以使用. 函数(方法)实例: 下面的例 ...

  3. Codeforces Round #364 (Div. 2) C.They Are Everywhere

    C. They Are Everywhere time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  4. elasticsearch快照和恢复

    摘要:es可以通过简单的命令对索引或者整个集群进行快照和恢复 快照和恢复 Snapshot and restore 模块允许创建单个索引或者整个集群的快照到远程仓库. 在初始版本里只支持共享文件系统的 ...

  5. PHP字符串函数试题

    Ctrl+A查看答案 1.把ASCII字符的字符串转换为十六进制值的函数是什么?答:bin2hex($string),例如bin2hex('ab') = 6162 2.ASCII码转字符,字符转ASC ...

  6. rs.Open sql,conn,0,2,1

    例子:rs.Open sql,conn,0,2,1 CursorType = 0,默认值,打开仅向前类型游标.LockType = 2, 开放式锁定Options = 1, 指示 ADO 生成 SQL ...

  7. sql server多行数据(一列)转换成一个字段

    create table #test ( id int not null, memeo int not null ) ,) ,) ,) )) ,,'') drop table #test 总结: 格式 ...

  8. js.map error

    1. 问题:      1.1 通过bower install 的components 许多在运行的时候报404无法找到js.map文件, 如图:          2. 分析:     2.1 查看 ...

  9. php杂乱

    //    //    if ( $_GET['action'] == 'search' ) {//        $_clean = array();//        $_clean['stype ...

  10. curl file_get_contents fsockopen

    三种处理的方式:     curl     file_get_contents     fsockopen fsockopen 是比较底层的调用,属于网络系统的socket调用,而curl经过的包装支 ...