题目介绍
题意 :输出在年龄(a,b)段内的m个富豪
思路:暴力的选择方法
对n个符号排序,在k此询问下找M个容易超时
所以将富豪按年龄段排
代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
const int N= 1003;
const int INF = 1e9+4;
/**看准数据的范围的暴力 方法一暴力超时 用方法二暴力*/
struct node{
string name;
int age,worth;
friend bool operator <(node a,node b)
{
if(a.worth!=b.worth){return a.worth>b.worth;}
return a.name<b.name;
}
};
vector <node >per[N];
int cur[202];
int main(){
int n,k;
cin>>n>>k;
string name;
int age,worth;
for(int i=0;i<n;++i){
cin>>name>>age>>worth;
per[age].push_back( node{name,age,worth} );
}
int cnt = 1;
for(int i=0;i<202;++i) sort(per[i].begin(),per[i].end());
while(k--){
int m,a,b;
scanf("%d %d %d",&m,&a,&b);
printf("Case #%d:\n",cnt++);
memset(cur,0,sizeof(cur));
bool f=false;
for(int j=0;j<m;++j){
int ans=-1,val=-INF;
for(int i=a;i<=b;++i){
if(per[i].size() > cur[i] && per[i][cur[i]].worth>val){
val = per[i][cur[i]].worth;
ans = i;
}
}
if(ans==-1)break;
f=true;
cout<<per[ans][cur[ans]].name<<' '<<ans<<' '<<per[ans][cur[ans]].worth<<endl;
cur[ans]++;
}
if(!f)cout<<"None"<<endl;
}
return 0;
}