pat_advanced level
来源:互联网 发布:阿里云域名接入备案 编辑:程序博客网 时间:2024/05/19 19:34
今日排名1244
pata_1053
用数组会超时,结构体不会,难道结构体存取会比数组快吗?
难以理解。。。。
pata_1055
前方有大坑。。。。。。。。。。
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <string.h>
using namespace std;
struct person{
char name[9];
short int age;
int worth;
};
vector<person> p[1002];
int book[210]={0};
bool cmp(person a,person b){
if(a.worth!=b.worth){
return a.worth>b.worth;
}
else{
if(a.age!=b.age){
return a.age<b.age;
}
else{
return strcmp(a.name,b.name)<0;
}
}
}
int main(){
int n,k;
//cin>>n>>k;
scanf("%d %d",&n,&k);
person somebody;
for(int i=0;i<n;++i){
// cin>>somebody.name>>somebody.age>>somebody.worth;
scanf("%s %d %d",somebody.name,&somebody.age,&somebody.worth);
p[0].push_back(somebody);
}
sort(p[0].begin(),p[0].end(),cmp);
for(int i=0;i<p[0].size();++i){
book[p[0][i].age]++;
if(book[p[0][i].age]<=100){
p[1001].push_back(p[0][i]);
}
}
for(int i=1;i<=k;++i){
short m,amin,amax;
// cin>>m>>amin>>amax;
scanf("%d %d %d",&m,&amin,&amax);
for(int j=0,md=0;j<p[1001].size();++j){
if(p[1001][j].age>=amin&&p[1001][j].age<=amax){
p[i].push_back(p[1001][j]);
md++;
if(md==100){
break;
}
}
}
//cout<<"Case"<<" #"<<i<<":"<<endl;
printf("Case #%d:\n",i);
if(p[i].size()==0){
// cout<<"None"<<endl;
printf("None\n");
}
int md;
//=m<p[i].size():m?p[i].size();
if(m>p[i].size()){
md=p[i].size();
}
else{
md=m;
}
for(int j=0;j<md;++j){
// cout<<p[i][j].name<<" "<<p[i][j].age<<" "<<p[i][j].worth<<endl;
printf("%s %d %d\n",p[i][j].name,p[i][j].age,p[i][j].worth);
}
}
return 0;
}
鬼想得到一个年龄平均有500人,而一个年龄段最多输出100人这种鬼。。。。。。。。。。。。。。。。。
做了两题,排名1189,好low。。。。。
1056不算难,但是头脑应该清晰,以免被自己搞混。。。。。。。。。。。
回去了
- pat_advanced level
- PAT_ADVANCED LEVEL 1002 多项式加法
- PAT_ADVANCED LEVEL 1071 C++ SLT MAP 小记
- PAT_ADVANCED LEVEL 1006 Sign In and Sign Out (25) 排序
- Log Level
- capture level
- BASIS Level..
- Isolation Level
- Alert Level
- info level
- syslog level
- Rococo(level )
- Oracle Level ?*
- level up
- tester level
- Warning Level
- isolation level
- RAID Level
- plsql使用技巧
- 蓝牙Bluetooth 5.0 室内定位 Indoor Position学习(三)
- 修改日期
- 课时70 Fragment shader - Alpha 与 blend 运算
- javascript中如何将对象转化为json字符串?
- pat_advanced level
- Spring的AOP常见错误
- FrameWork层WiFi模块架构剖析
- SpringMVC @RequestBody接收Json对象字符串
- oracle 索引的缺点和优点
- Singleton bean creation not allowed while the singletons of this factory are in destruction (Do not
- NPOI选择框
- 自定义View---自定义进度条
- Xcode8 注释 快捷键