您的位置:首页 > 其它

CodeForces - 799C

2017-11-27 11:03 344 查看
这题也是参考别人想法写出来的,好菜啊。。。

思路:每次先选定一个够钱建造的喷泉,然后从剩下的里面选造价不超过剩余财富的,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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: