codeforces #436 A Feed with Candy(贪心)
来源:互联网 发布:知乎体格式 编辑:程序博客网 时间:2024/06/10 06:46
题目地址:http://codeforces.com/contest/436/problem/A
自己笨的要死。。。WA了好多次,还是看题解才明白了。。。一直在纠结该先选0好还是先选1好,但是就是没想到可以枚举这两种情况都试一试。。。
分别枚举这两种情况,然后每次选的时候从另一种糖果里从可以够到的糖果里选出m最大的那个,贪心就可以了。
代码如下:
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;struct node{ int x, h, m;} fei[3000];int _hash[3000], a[3];int cmp(node x, node y){ return x.m>y.m;}int main(){ int n, h, i, j, tot, x, m, max1=-1; scanf("%d%d",&n,&m); for(i=0; i<n; i++) { scanf("%d%d%d",&fei[i].x,&fei[i].h,&fei[i].m); } sort(fei,fei+n,cmp); for(j=0; j<2; j++) { tot=0; h=m; memset(_hash,0,sizeof(_hash)); x=j; while(1) { int flag=0; for(i=0; i<n; i++) { if(!_hash[i]&&fei[i].h<=h&&fei[i].x!=x) { h+=fei[i].m; tot++; flag=1; x=fei[i].x; _hash[i]=1; break; } } if(!flag) break; } max1=max(max1,tot); } printf("%d\n",max1); return 0;}
2 0
- codeforces #436 A Feed with Candy(贪心)
- codeforces A. Feed with Candy
- A. Feed with Candy
- CF A. Feed with Candy
- Zepto Code Rush 2014-A. Feed with Candy(HACK)
- Feed with Candy
- CF Zepto Code Rush 2014 A - Feed with Candy
- cf Feed with Candy 这题做的都想哭
- HDU 5380 Travel with candy (单调队列&贪心)
- codeforces 334A. Candy Bags
- CodeForces 334A Candy Bags
- hdu 5380 Travel with candy 贪心&队列
- Codeforces Round #436 D.Make a Permutation!(贪心)
- CodeForces #194 Div.2 A. Candy Bags
- codeforces-230A-Dragons(贪心+排序)
- Codeforces 383A Milking cows(贪心)
- Codeforces 383 A. Milking cows(贪心)
- codeforces 67A Partial Teacher( 贪心)
- 认识SylixOS
- 堆与堆排序
- Timer定时器
- 两层容器的position 之间的关系
- 如何查询占用端口的程序进程
- codeforces #436 A Feed with Candy(贪心)
- GPU并行编程方法
- SQLAlchemy实战详解
- SQL点滴26—常见T-SQL面试解析
- Add Binary
- Android service详解(一)
- hdu3468 splay
- mongoVUE 数据的json格式导入导出
- zoj 2158 Truck History(最小生成树))