【PAT甲级】1055 The World's Richest (25 分)
题意:
输入两个正整数N和K(N<=1e5,K<=1000),接着输入N行,每行包括一位老板的名字,年龄和财富。K次询问,每次输入三个正整数M,L,R(M<=100,L,R<=200),输出至多M位年龄区间在L,R之间的老板的名字年龄和财富,按照财富降序,年龄升序,姓名字典序输出。
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
string s;
typedef struct account{
string name;
int age,worth;
};
bool cmp(account a,account b){
if(a.worth!=b.worth)
return a.worth>b.worth;
if(a.age!=b.age)
return a.age<b.age;
return a.name<b.name;
}
vector<account>vv;
vector<account>v;
int sum[];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,k;
cin>>n>>k;
int age,w;
for(int i=;i<=n;++i){
cin>>s>>age>>w;
account tamp;
tamp.name=s;
tamp.age=age;
tamp.worth=w;
vv.push_back(tamp);
}
int x,l,r;
sort(vv.begin(),vv.end(),cmp);
for(int i=;i<vv.size();++i)//根据数据规模优化,大幅缩短运行时间
if(sum[vv[i].age]<){
v.push_back(vv[i]);
++sum[vv[i].age];
}
for(int i=;i<=k;++i){
cin>>x>>l>>r;
cout<<"Case #"<<i<<":\n";
int flag=;
for(int j=;j<v.size();++j){
if(v[j].age>=l&&v[j].age<=r){
cout<<v[j].name<<" "<<v[j].age<<" "<<v[j].worth<<"\n";
--x;
flag=;
}
if(!x)
break;
}
if(!flag)
cout<<"None\n";
}
return ;
}
【PAT甲级】1055 The World's Richest (25 分)的更多相关文章
- PAT 甲级 1055 The World's Richest (25 分)(简单题,要用printf和scanf,否则超时,string 的输入输出要注意)
1055 The World's Richest (25 分) Forbes magazine publishes every year its list of billionaires base ...
- PAT甲级:1036 Boys vs Girls (25分)
PAT甲级:1036 Boys vs Girls (25分) 题干 This time you are asked to tell the difference between the lowest ...
- PAT甲级:1089 Insert or Merge (25分)
PAT甲级:1089 Insert or Merge (25分) 题干 According to Wikipedia: Insertion sort iterates, consuming one i ...
- PAT 甲级 1145 Hashing - Average Search Time (25 分)(读不懂题,也没听说过平方探测法解决哈希冲突。。。感觉题目也有点问题)
1145 Hashing - Average Search Time (25 分) The task of this problem is simple: insert a sequence of ...
- PAT 甲级 1066 Root of AVL Tree (25 分)(快速掌握平衡二叉树的旋转,内含代码和注解)***
1066 Root of AVL Tree (25 分) An AVL tree is a self-balancing binary search tree. In an AVL tree, t ...
- PAT 甲级 1047 Student List for Course (25 分)(cout超时,string scanf printf注意点,字符串哈希反哈希)
1047 Student List for Course (25 分) Zhejiang University has 40,000 students and provides 2,500 cou ...
- PAT 甲级 1039 Course List for Student (25 分)(字符串哈希,优先队列,没想到是哈希)*
1039 Course List for Student (25 分) Zhejiang University has 40000 students and provides 2500 cours ...
- PAT (Advanced Level) Practice 1055 The World's Richest (25 分) (结构体排序)
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...
- PAT甲级1055 The World's Richest【排序】
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805421066272768 题意: 给定n个人的名字,年龄和身价. ...
随机推荐
- C++算法导论第九章O(n)期望选择序列第i小的数字
#include<iostream> #include<vector> #include<algorithm> #include<time.h> usi ...
- poj 1611 :The Suspects经典的并查集题目
Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized ...
- Js将字符串转换成对象或数组en
举个例子 var test='{ colkey: "col", colsinfo: "NameList" }' a.将文本转换成对象 var test='{ c ...
- HPS—虚拟地址映射
HPS 如何对FPGA外设进行操作?hardware:在Qsys中将外设连接到AXI bridge上software:映射外设物理地址到到应用程序可以操作的虚拟地址,应用程序通过得到的虚拟地址入口控制 ...
- 6_11 四分树(UVa297)<四分树>
一幅图有1024个点, 可以对图平均分成4块, 并且子图也可以再往下分, 直到一个子图表示一个点. f表示这块子图填满, p表示它还有4个子图, e表示没有子图(当然啦, 它也没有填满). 给定两个字 ...
- springmvc validator和springContext validator的区别
1.springContext validator 依赖于代理实现 MethodValidationInterceptor Set<ConstraintViolation<Object&g ...
- 使用prepareStatement执行的sql语句的写法:
使用prepareStatement对象执行的增.删.改.查sql语句: 查: String sql = "SELECT * FROM 表名 WHERE loginId=? AND pas ...
- ACM-ICPC实验室20.2.21测试-图论(二)
A.患者的编号 给出一个有向图,要求你输出字典序最小的拓扑排序. 常规拓扑排序是做不了的,正解是反向建图,同时用大根堆的优先队列维护,保证每次优先访问编号大的结点,再反向输出~ #include< ...
- redis哈希操作
用户可以通过执行hset命令为哈希中的指定字段设置值: 127.0.0.1:6379> hset hash field value 根据给定的字段是否存在于散列中,hset命令的行为也会有所不同 ...
- 升级 .net core3.1
下载sdk3.1版本 升级包 然后build之后看提示若有其他包版本太低则按照提示将其他包升级 build --> run 报错,修复bug(主要由于包更新之后有些方法或者属性被移除造成无法使用 ...