sicily1134 分发积木问题 使用struct能够节省很多定义数组,代码简洁也容易想. 但是在C++2008编译过了之后再sicily上一直是编译错误.后来一排查是因为const的关系.其实这是代码习惯的问题,为了防止改变对象的值.I guess. #include <iostream> #include <algorithm> using namespace std; struct Rec { int x,y; }a[10000]={0}; bool cmp(const Rec& a,const Rec& b)//一定要加const,不然会出现编译错误(sicily上) { return a.y<b.y; } int main() { int n,s; bool boole; while(cin>>n>>s) { if(n==0) break; else { boole =true; for(int j=0;j<n;j++) cin>>a[j].x>>a[j].y; sort(a,a+n,cmp); for(int i=0;i<n;i++) { if(s<a[i].y) { boole = false; break; } s+=a[i].x; } } if(boole) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }