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 ...
随机推荐
- VS中的快捷键快速格式化代码,使好看,整齐
在VC2005中,快捷键是Ctrl + K, Ctrl + F, 这是一个组合键,即先按Ctrl + K, 这时候编辑器会等待下一个按键动作,此时再按Ctrl + F, 即可以格式化代码了,当然,也可 ...
- Java编程中时区和时间相关的问题
先说一个结论:时间戳是一个和时区无关的东西,在哪里都是一致的!但是转化为字符串之后,就和时区有关系了. 以下为内容: 参考链接:http://m.blog.csdn.net/article/detai ...
- 第二十六节,Python内置函数
Python3.0内置函数 abs() 取数字的绝对值,也就是无论是正数还是负数取它的绝对值格式:abs(目标变量)返回:数字类型 #!/usr/bin/env python # -*- coding ...
- LeetCode OJ 110. Balanced Binary Tree
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...
- SharePoint 2010 应用url参数过滤列表视图数据(应用get办法过滤列表数据)
名人名言:读活书,活读书,读书活.——郭沫若 题目其实不知道如何称呼才干合适大师的搜刮习惯.以便有类似题目经由过程百度或google可以搜刮到,其实就是在url后面添加参数过滤显示我们想要的成果,有人 ...
- shell之路【第一篇】shell简介与入门
shell简介 1.Shell 诞生于 Unix,Unix的第一个脚本语言,是与 Unix/Linux 交互的工具,单独地学习 Shell 是没有意义的,shell使用的熟练程度反映了用户对Unix/ ...
- PHP实现队列的原理
关于的队列的介绍,我这里就不多讲了,随便百度一下都很多 用过laravel框架的童鞋都知道其自带队列功能,之前我很费解,PHP只是一个脚本,有超时机制 为什么能不停的去执行队列呢? 带着这个问题,在网 ...
- QT插件和服务培训
下载地址:http://files.cnblogs.com/files/senior-engineer/%E6%8F%92%E4%BB%B6%E5%92%8C%E6%9C%8D%E5%8A%A1%E5 ...
- XTEA加密算法
XTEA加密算法 #include <stdint.h> /* take 64 bits of data in v[0] and v[1] and 128 bits of key[0] - ...
- hibernate —— 树状存储
package com.pt.treeStrut; import java.util.Set; import javax.persistence.CascadeType; import javax.p ...