PAT (Advanced Level) 1055. The World's Richest (25)
排序。随便加点优化就能过。
#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)的更多相关文章
- 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 ...
- 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 ...
- PAT (Advanced Level) 1102. Invert a Binary Tree (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT (Advanced Level) 1098. Insertion or Heap Sort (25)
简单题.判断一下是插排还是堆排. #include<cstdio> #include<cstring> #include<cmath> #include<ve ...
- PAT (Advanced Level) 1067. Sort with Swap(0,*) (25)
只对没有归位的数进行交换. 分两种情况: 如果0在最前面,那么随便拿一个没有归位的数和0交换位置. 如果0不在最前面,那么必然可以归位一个数字,将那个数字归位. 这样模拟一下即可. #include& ...
- PAT (Advanced Level) 1066. Root of AVL Tree (25)
AVL树的旋转.居然1A了.... 了解旋转方式之后,数据较小可以当做模拟写. #include<cstdio> #include<cstring> #include<c ...
- PAT (Advanced Level) 1047. Student List for Course (25)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- PAT (Advanced Level) 1082. Read Number in Chinese (25)
模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT (Advanced Level) 1002. A+B for Polynomials (25)
为0的不要输出. #include<iostream> #include<cstring> #include<cmath> #include<algorith ...
随机推荐
- 下载google play上的APP
googol搜索 download apk directly,然后即可看到
- 访问nginx-php页面的时候 报access denied.
访问页面的时候出现这个时access denied 只需到/usr/local/php/etc/php.ini中修改一下 把这个注释掉 ;open_basedir = 把这个值赋值为1 cgi.f ...
- 循环ip段 转载 出处不明
public struct IP { public byte A; public byte B; public ...
- JavaConcurrentHashMap
JavaConcurrentHashMap 大滕翼不自觉地往前探了探身子可还没等他听到唐寅说到 兆咒耶Т √靼脶摹 す宿坩曹 '字'心'上都有横您老瞧瞧这个'宣德 炔灌莞 蹇忄в 幼銮亿辽 仄黛境 ...
- vb6 控件未注册问题解决
打开项目时弹出如题错误. 另附一个帖子:http://bbs.csdn.net/topics/390580540,这个帖子讨论的不错,可以提供很多思路. 解决办法:http://rewwensoftw ...
- wpf 类似TextBlock外观的Button的样式
<Style x:Key="noborderbtnStyle" TargetType="{x:Type Button}"> <Setter P ...
- 天天果园,中粮我买网等生鲜APP竞品分析
奈何对生鲜行业的品类,价格,供应链不熟悉,想先从APP开始来了解生鲜行业和各个生鲜企业,若有不足之处,还望海量,也请帮忙指正. 选取了以下竞品:天天果园,易果生鲜,一米鲜,中粮我买网,爱鲜蜂,每日优鲜 ...
- Keychain 浅析
什么是Keychain? 根据苹果的介绍,iOS设备中的Keychain是一个安全的存储容器,可以用来为不同应用保存敏感信息比如用户名,密码,网络密码,认证令牌.苹果自己用keychain来保存Wi- ...
- iOS8中的动态文本
原文链接 : Swift Programming 101: Mastering Dynamic Type in iOS 8 原文作者 : Kevin McNeish Apple声称鼓励第三方App能够 ...
- ntp源码解读(一)
/* * session_key - generate session key * * This routine generates a session key from the source add ...