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

#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. Table隔行变色的JavaScript代码

    <table id="datatable"> <tr> <td>脚本之家</td> </tr> <tr> & ...

  2. @Value 注解获取properties值

    转自:使用Spring 3的@value简化配置文件的读取 Spring 3支持@value注解的方式获取properties文件中的配置值,大简化了读取配置文件的代码. 1.在application ...

  3. 查看使用了那种shell

    cat /etc/shells  root@OpenWrt:/www/cgi-bin# cat /etc/shells/bin/ash

  4. POJ2524:Ubiquitous Religions (并查集模板)

    Description There are so many different religions in the world today that it is difficult to keep tr ...

  5. siege

    SIEGE 3.0.0Usage: siege [options] siege [options] URL siege -g URLOptions: -V, --version VERSION, pr ...

  6. javascript模糊查询一个数组

    /* * 模糊查询一个数组 */ com.ty.repairtech.JsonOperation.searchList = function(str, container) { var newList ...

  7. 微信支付WxpayAPI_php_v3(二)支付功能开发

    这里我没有开发openid和acessToken的获取,需要的请参考文档获取. 在阅读本教程之前请熟读微信支付的开发者文档. 直接开始[统一下单],在实际开发的项目中一般都有mvc分层的开发思想. 根 ...

  8. 解决在IIS中调用Microsoft Office Excel组件后进程无法正常退出的问题

    来源:http://www.cnblogs.com/ahui/archive/2013/03/05/2944441.html 有一个项目用到Excel组件产生报表,本以为这个通用功能是个很简单的cas ...

  9. PHP基本类型操作

    //关键字对大小写不敏感echo ('hello world!<br>');ECho ('hello world<br>');eCho ('hello world<br& ...

  10. iOS真机测试中出现dyld`dyld_fatal_error错误

    最近进入一家新公司,接手了一个之前由外包公司承接的项目.首先吐槽一下项目质量,哎毕竟也憋了很久了. 1.上手项目是打不开的,所有framework静态库全体飘红,一编译七八十错误.最终是偷懒还是什么就 ...