1055 The World's Richest (25 分)

1055 The World's Richest (25 分)

题目介绍

题意 :输出在年龄(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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值