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 ...
随机推荐
- Linux下将Mysql和Apache加入到系统服务里的方法
Apache加入到系统服务里面: cp /安装目录下/apache/bin/apachectl /etc/rc.d/init.d/httpd 修改httpd 在文件头部加入如下内容: ### # Co ...
- js算数方法
原文:http://www.w3school.com.cn/js/js_obj_math.asp 除了可被 Math 对象访问的算数值以外,还有几个函数(方法)可以使用. 函数(方法)实例: 下面的例 ...
- 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 ...
- elasticsearch快照和恢复
摘要:es可以通过简单的命令对索引或者整个集群进行快照和恢复 快照和恢复 Snapshot and restore 模块允许创建单个索引或者整个集群的快照到远程仓库. 在初始版本里只支持共享文件系统的 ...
- PHP字符串函数试题
Ctrl+A查看答案 1.把ASCII字符的字符串转换为十六进制值的函数是什么?答:bin2hex($string),例如bin2hex('ab') = 6162 2.ASCII码转字符,字符转ASC ...
- rs.Open sql,conn,0,2,1
例子:rs.Open sql,conn,0,2,1 CursorType = 0,默认值,打开仅向前类型游标.LockType = 2, 开放式锁定Options = 1, 指示 ADO 生成 SQL ...
- sql server多行数据(一列)转换成一个字段
create table #test ( id int not null, memeo int not null ) ,) ,) ,) )) ,,'') drop table #test 总结: 格式 ...
- js.map error
1. 问题: 1.1 通过bower install 的components 许多在运行的时候报404无法找到js.map文件, 如图: 2. 分析: 2.1 查看 ...
- php杂乱
// // if ( $_GET['action'] == 'search' ) {// $_clean = array();// $_clean['stype ...
- curl file_get_contents fsockopen
三种处理的方式: curl file_get_contents fsockopen fsockopen 是比较底层的调用,属于网络系统的socket调用,而curl经过的包装支 ...