PAT Advanced Level 1055
来源:互联网 发布:云宝网是网络传销吗 编辑:程序博客网 时间:2024/06/06 01:52
题目地址:http://pat.zju.edu.cn/contests/pat-a-practise/1055
思路分析:主要注意超时的问题,给出了输出限制,应该先按财富排序而非年龄排序,即使使用二分查找同样超时
代码如下:
#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;struct richer{ char name[9]; int age; int money;};int n,q;richer v[100001];int avail[100001];int ageRank[201];int cmpMon(richer A,richer B){ if(A.money!=B.money) return A.money>B.money; else{ if(A.age!=B.age) return A.age<B.age; else return strcmp(A.name,B.name)<0; }}int main(){ //freopen("C:\\Users\\Devon\\Desktop\\input.txt","r",stdin); memset(avail,0,sizeof(avail)); memset(ageRank,0,sizeof(ageRank)); scanf("%d%d",&n,&q); for(int i=0;i<n;i++) scanf("%s%d%d",v[i].name,&v[i].age,&v[i].money); sort(v,v+n,cmpMon); int cur=0; for(int i=0;i<n;i++){ ageRank[v[i].age]++;//用例2测试最大输出 if(ageRank[v[i].age]<101) avail[cur++]=i; } for(int i=0;i<q;i++){ printf("Case #%d:\n",i+1); int num,young,old; scanf("%d%d%d",&num,&young,&old); int flag=1; for(int j=0;j<cur;j++){ int x=avail[j]; if(v[x].age<=old&&v[x].age>=young) num--,flag=0,printf("%s %d %d\n",v[x].name,v[x].age,v[x].money); if(num==0) break; } if(flag) printf("None\n"); } return 0;}
0 0
- PAT Advanced Level 1055
- PAT Advanced Level 1077
- PAT Advanced Level 1078
- PAT Advanced Level 1079
- PAT Advanced Level 1080
- PAT Advanced Level 1010
- PAT Advanced Level 1016
- PAT Advanced Level 1018
- PAT Advanced Level 1039
- PAT Advanced Level 1060
- PAT Advanced Level 1026
- PAT Advanced Level 1029
- PAT Advanced Level 1030
- PAT Advanced Level 1033
- PAT Advanced Level 1034
- PAT Advanced Level 1038
- PAT Advanced Level 1045
- PAT Advanced Level 1049
- 的时光三等功时光
- android 反编译和代码解读
- Mybatis的介绍
- QT创建工程时不存在Kits的解决方案
- linux文件时间的查看和修改touch
- PAT Advanced Level 1055
- Wireshark学习笔记——如何快速抓取HTTP数据包
- UVa11506 - Angry Programmer(ISAP)
- SuSe Linux防火墙配置指定IP或IP段可访问
- 真理名言
- codeforces做题笔记
- linux(ubuntu)中的命令
- PAT Advanced Level 1056
- scrapy配置过程遇到的问题以及解决--002