SRM 608 D2 L2:MysticAndCandiesEasy

时间:2014-02-09 15:54:20   收藏:0   阅读:326

题目:http://community.topcoder.com/stat?c=problem_statement&pm=12998


代码:

#include <algorithm>
#include <iostream>
#include <sstream>

#include <string>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <ctime>

using namespace std;


#define CHECKTIME() printf("%.2lf\n", (double)clock() / CLOCKS_PER_SEC)

/*************** Program Begin **********************/

class MysticAndCandiesEasy {
public:
    int minBoxes(int C, int X, vector <int> high) {
        int res = 0;
	int N = high.size();

	sort(high.begin(), high.end());
	int sum = 0;
	for (int i = 0; i < N; i++) {
		sum += high[i];
	}
	int dif = sum - C;
	reverse(high.begin(), high.end());
	int eat = 0;
	for (int i = 0; i < N; i++) {
		eat += high[i];
		if (eat - dif >= X) {
			res = i + 1;
			break;
		}
	}

        return res;
    }

};


/************** Program End ************************/


原文:http://blog.csdn.net/xzz_hust/article/details/18988969

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!