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 ...
随机推荐
- 缺少对象 WScript 问题解决方法
方法一: 先把脚本保存起来(保证你的脚本能正确运行),例如命名为test.vbs 然后在QTP写以下脚本就可以正确运行了! Dim oShell Set oShell =CreateObject (& ...
- shell脚本学习(二)
4.cat命令 1) cat -s 摆脱多余的空白行 2) cat -T 将制表符显示为^I 3) cat -n 显示行号 4) cat -b 跳过空白行,然后显示行号 ...
- 触动精灵 alilib
--gethtml function gethtml (url) local sz = require("sz") local http = require("szock ...
- Shell脚本,自动化发布tomcat项目【转】
Shell脚本,自动化发布tomcat项目脚本. 1. vko2c_auto_build_by_scp.sh 文件内容: #---------------------start------------ ...
- PHP文件相关函数试题
一.问答题 1.返回路径中的文件名部分的函数是什么? 2.改变文件模式的函数是什么? 3.拷贝文件的函数是什么? 4.返回路径中的目录部分的函数是什么? 5.将上传的文件移动到指定位置的函数是? 6. ...
- centos mono
wget http://download.mono-project.com/sources/mono/mono-4.0.1.tar.bz2wget http://download.mono-proje ...
- 689C - Mike and Chocolate Thieves 二分
题目大意:有四个小偷,第一个小偷偷a个巧克力,后面几个小偷依次偷a*k,a*k*k,a*k*k*k个巧克力,现在知道小偷有n中偷法,求在这n种偷法中偷得最多的小偷的所偷的最小值. 题目思路:二分查找偷 ...
- linux的学习系列 10---vi
Linux下的文本编辑器有很多种,vi 是最常用的,也是各版本Linux的标配.注意,vi 仅仅是一个文本编辑器,可以给字符着色,可以自动补全,但是不像 Windows 下的 word 有排版功能. ...
- mysql中exists的用法介绍
SELECT c.CustomerId, CompanyName 2 FROM Customers c 3 WHERE EXISTS( 4 SELECT OrderID FROM ...
- ScrollView嵌套ViewPager 时候 Pager左右滑动不流畅
//触摸事件 pager.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v ...