CodeForces
来源:互联网 发布:摄像机内存卡数据恢复 编辑:程序博客网 时间:2024/05/19 16:29
这题也是参考别人想法写出来的,好菜啊。。。
思路:每次先选定一个够钱建造的喷泉,然后从剩下的里面选造价不超过剩余财富的,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;}
阅读全文
0 0
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Java工厂设计模式
- html5--h5的改进优势
- Spring的监听事件ApplicationListener和ApplicationEvent及@EventListener用法
- ASP 最简单导出excel的方法
- java.lang.NoSuchMethodError
- CodeForces
- javascript函数细说,函数也能做对象
- InstantiationAwareBeanPostProcessor
- java抽象类和接口干货满满
- JAVA之经典算法一
- liunx 操作命令记录
- Java(8-3 01)多线程同步
- Python爬虫学习(八)爬网页文字信息
- excel公式使用记录