`
txf2004
  • 浏览: 6854608 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

【二分枚举】杭电 hdu 4190 Distributing Ballot Boxes

 
阅读更多


/* THE PROGRAM IS MADE BY PYY */
/*----------------------------------------------------------------------------//
    Copyright (c) 2012 panyanyany All rights reserved.

    URL   : http://acm.hdu.edu.cn/showproblem.php?pid=4190
    Name  : 4190 Distributing Ballot Boxes

    Date  : Monday, April 02, 2012
    Time Stage : 1 hour

    Result:
5691701	2012-04-02 19:37:39	Accepted	4190
375MS	2204K	1434 B
C++	pyy


Test Data :

Review :
受华神指导,终于AC了……
//----------------------------------------------------------------------------*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>

#include <algorithm>
#include <iostream>
#include <queue>

using namespace std ;

#define MEM(a, v)        memset (a, v, sizeof (a))    // a for address, v for value
#define max(x, y)        ((x) > (y) ? (x) : (y))
#define min(x, y)        ((x) < (y) ? (x) : (y))

#define INF     (0x3f3f3f3f)
#define MAXN    (500002)

#define DB    /##/
#define LL __int64

int		n, b;
int		Max, Min, Mid;
int		city[MAXN];

int solve()
{
	int i, t = b;
	for (i = 0; i < n; ++i)
	{
		int r = city[i] / Mid;
		if (city[i] % Mid)
		{
			++r;
		}
		t -= r;
	}
	return t;
}

int main()
{
	int i;
	while (scanf("%d %d", &n, &b), n != -1 && b != -1)
	{
		Max = 0;
		Min = 1;
		for (i = 0; i < n; ++i)
		{
			scanf("%d", &city[i]);
			Max = max(Max, city[i]);
		}
		Max++;
		while (Min < Max)
		{
			Mid = (Min + Max) / 2;
			if (solve() < 0)
				Min = Mid + 1;
			else  // 箱子可以不用完~一开始以为必须分完,结果屡次WA
				Max = Mid;
		}
		printf ("%d\n", Max);
	}
	return 0;
}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics