CodeForces - 799C

这题也是参考别人想法写出来的,好菜啊。。。

思路:每次先选定一个够钱建造的喷泉,然后从剩下的里面选造价不超过剩余财富的,beauty值最高的。为了不重复要先进行排序,排序按美丽度从小到大,美丽度相同的情况下花费小的在前面。如果只找到一个或一个都找不到就输出0;

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn=1e5+50;
int n,c,d,b,cost,left,cnt,maxs;
char type;

struct fountain{
    int b,cost;
    char type;
};
fountain f[maxn];

bool cmp(fountain a,fountain b){
    if(a.b==b.b)
        return a.cost<b.cost;
    return a.b>b.b;
}

int main(){
    while(scanf("%d%d%d",&n,&c,&d)!=EOF){
        maxs=0;
        for(int i=0;i<n;i++){
            scanf("%d%d%*c%c",&b,&cost,&type);
            f[i].b=b;
            f[i].cost=cost;
            f[i].type=type;
        }
        sort(f,f+n,cmp);
        for(int i=0;i<n;i++){
          int t1=c;
          int t2=d;
          if(f[i].type=='C'&&t1<=f[i].cost)
            continue;
          else if(f[i].type=='D'&&t2<=f[i].cost)
            continue;
          if(f[i].type=='C'&&t1>f[i].cost)
            {t1-=f[i].cost;
             cnt=0;
             cnt+=f[i].b;
            }
          else if(f[i].type=='D'&&t2>f[i].cost)
            {t2-=f[i].cost;cnt=0;cnt+=f[i].b;}
          for(int j=i+1;j<n;j++){
            if(f[j].type=='C'&&f[j].cost<=t1){
                cnt+=f[j].b;
                maxs=max(maxs,cnt);
                break;
            }
            else if(f[j].type=='D'&&f[j].cost<=t2){
                cnt+=f[j].b;
                maxs=max(maxs,cnt);
                break;
            }
        }
        }
        printf("%d\n",maxs);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值