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

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<map>
#include<queue>
#include<string>
#include<stack>
#include<vector>
using namespace std; struct X
{
char name[];
int age;
int val;
}s[+];
int n,k,cnt;
int ans[+]; bool cmp(const int &a,const int &b)
{
if(s[a].val==s[b].val&&s[a].age==s[b].age)
return strcmp(s[a].name,s[b].name)<;
if(s[a].val==s[b].val) return s[a].age<s[b].age;
return s[a].val>s[b].val;
} bool CMP(const X&a,const X&b)
{
if(a.val==b.val&&a.age==b.age)
return strcmp(a.name,b.name)<;
if(a.val==b.val) return a.age<b.age;
return a.val>b.val;
} int main()
{
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++)
scanf("%s%d%d",s[i].name,&s[i].age,&s[i].val);
sort(s+,s++n,CMP);
for(int i=;i<=k;i++)
{
int a,b,c; scanf("%d%d%d",&a,&b,&c);
cnt=;
for(int j=;j<=n;j++){
if(s[j].age>=b&&s[j].age<=c) ans[cnt++]=j;
if(cnt==a) break;
}
printf("Case #%d:\n",i);
if(cnt==) printf("None\n");
else
{
sort(ans,ans+cnt,cmp);
for(int j=;j<min(a,cnt);j++)
printf("%s %d %d\n",s[ans[j]].name,s[ans[j]].age,s[ans[j]].val);
}
}
return ;
}

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. php文件去重复,二维数组筛选

    http://www.porter.com/fr/fr/product/648162|Sneakershttp://www.porter.com/fr/fr/product/642115|Bootsh ...

  2. vhost.sh 源代码,认真看哦

    #!/bin/bash # # Web Server Install Script # Created by wdlinux QQ:12571192 # Url:http://www.wdlinux. ...

  3. 将GridView导入到Excel

    前几天做项目需要用到将GridView中的数据导入到Excel,原以为很简单,上网搜了一下资料,果然方法不少,于是就采用了一个: private void GridViewToExcel() { Re ...

  4. 《JS权威指南学习总结--4.9.3in和instanceof运算符》

    内容要点: 一.in运算符 in运算符希望它的左操作数是一个字符串或可以转换为字符串,希望它的右操作数是一个对象.如果右侧的对象拥有一个名为左操作数数值的属性名,那么表达式返回true. 例如: va ...

  5. hdu_5750_Dertouzos(线性筛)

    题目连接:hdu_5750_Dertouzos 题意: 给你一个n,一个d,问你比n小的数中有多少个数的最大的因子为d,比如6有因子1 2 3 最大的为3 题解: 当时比赛做这题的时候没考虑常数的优化 ...

  6. CentOS 7 BIND 搭建

    域名查找顺序 设置 /etc/host.conf 1. bind 安装 $ yum install bind bind-utilsnslookup (name server lookup) 在bind ...

  7. .NET Framework不同组件区别及安装注意事项

      发布时间:  2012/7/14 11:52:37 严格细分起来,.NET Framework又有两个不同的组件,.NET Framework可再发行组件包(23MB左右)和.NET Framew ...

  8. jmx additional port

    http://stackoverflow.com/questions/20884353/why-java-opens-3-ports-when-jmx-is-configured http://blo ...

  9. ng-if 和 ng-show/ng-hide 之间的区别

    ng-if会移除dom,生成dom,而ng-show只是改变其display属性.所以你自己看着用吧.

  10. layer属性

    键: 值 描述 下表的属性都是默认值,您可在调用时按需重新配置,他们可帮助你实现各式各样的风格.如是调用: $.layer({键: 值, 键: 值, -}); type: 0 层的类型.0:信息框(默 ...