首页 > 其他 > 详细

SRM 608 D2 L2:MysticAndCandiesEasy

时间:2014-02-09 15:54:20      阅读:325      评论:0      收藏:0      [点我收藏+]

题目: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 ************************/


SRM 608 D2 L2:MysticAndCandiesEasy

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!