Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
两个错误:一是不小心;二是太不小心In Reply To:那位大牛救救我!受不了了!到底哪错了!总过不去!不胜感激! Posted by:li4951 at 2009-02-22 16:12:16 #include<iostream> #include<algorithm> using namespace std; int main() { int testcases = 0; int t = 1; // freopen("2487.txt", "r", stdin); cin >>testcases; while(testcases) { int sum = 0; int need = 0; int peonum = 0; int sign = 0; cin >> need >>peonum; int *data; data = new int[peonum]; int i = 0; for(i = 0; i < peonum; i++) { cin >>data[i]; } sort(data, data + peonum); // for(i = peonum - 1; i = 0; i--) for(i = peonum - 1; i >= 0; i--) { sum += data[i]; if((sum >= need) ) { sign = 1; break; } } cout << "Scenario #" << t++ << ":" << endl; if(sign == 1) { /*cout << (peonum - 1) - i << endl;*/ cout << (peonum - 1) - i +1 << endl; } else cout << "impossible" <<endl; testcases--; cout << endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator