POJ 1017 Packets (贪心)

POJ 1017


参考博客:http://blog.csdn.net/dongfengkuayue/article/details/6461374


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define eps 1e-8
using namespace std;
int main() {
	int num[7];
	int for2[4] = {0, 5, 3, 1};
	while(1) {
		int i, j;
		int sum = 0;
		for(i = 1; i <= 6; i++) {
			scanf("%d", num + i);
			sum += num[i];
		}
		if(!sum) break;
		int n = 0, left1 = 0, left2 = 0;
		n += num[6] + num[5] + num[4] + (num[3] + 3) / 4;
		left2 += 5 * num[4] + for2[num[3] % 4];
		if(num[2] > left2) n += (num[2] - left2 + 8) / 9;
		left1 = 36 * n - 36 * num[6] -  25 * num[5] - 16 * num[4] - 9 * num[3] - 4 * num[2];
		if(num[1] > left1) n += (num[1] - left1 + 35) / 36;
		printf("%d\n", n);
	}
	return 0;
}


你可能感兴趣的:(POJ 1017 Packets (贪心))