Sicily 1134 积木分发
2013-01-05 17:27
525 查看
/* 把所有孩子按照需要积木的量从小到大排序,依次加上歌星手里的积木即可 还以为用long会不够精度,结果居然过了 */ /* Passed all 4 test cases Run Time: 0.31secs Run Memory: 444KB */ #include <iostream> #include <algorithm> //sort等 #include <vector> using namespace std; typedef struct Child{ long a; //孩子拥有的木头数 long b; //孩子还需要的木头数 }; vector<Child> children; int cmp(Child a, Child b){ return a.b < b.b; } long N; //孩子数 1-10000 long S; //歌星拥有木头数 1-1000000 void compute(){ sort(children.begin(), children.end(), cmp); for(int i=0; i<children.size(); i++){ if(S >= children[i].b){ S += children[i].a; }else{ cout << "NO" << endl; return; } } cout << "YES" << endl; } int main() { while (cin>>N && N){ cin >> S; if(children.size() != 0) children.clear(); for(int i=0; i<N; i++){ Child buf; cin >> buf.a >> buf.b; children.push_back(buf); } compute(); } return 0; }
相关文章推荐
- [sicily][排序]1134. 积木分发
- Sicily 1134 积木分发
- Sicily1134——积木分发
- Sicily 1134. 积木分发
- sicily 1134.积木分发
- Sicily 1134. 积木分发
- Sicily 1134 积木分发
- Sicily 1134 积木分发
- [sicily]1134. 积木分发
- sicily 1134 积木分发
- sicily 1134. 积木分发
- sicily 1134. 积木分发
- sicily--1134 积木分发
- sicily1134.积木分发
- Sicily 1134 积木分发
- Sicily 1134. 积木分发
- sicily 1134 积木分发
- Sicily 1134.积木分发
- <OJ_Sicily>1134积木分发
- soj - 1134 - 积木分发