hdu4190 简单二分

题意是

有n个城市,m个投票箱,接下来n个城市人口数,每个投票箱都不能为空,计算最后投票箱的容量必须达到多少,才能满足需要。 每个城市的人必须只能将票投到自己城市分得得投票箱中。要是容量最小箱子必须得都用上

二分枚举所以的人数

#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;

int num[500100],n,m;
int judge(int x)
{
    int s=0;
    for(int i=1;i<=n;i++)
    {
        s+=num[i]/x;
        if(num[i]%x!=0) s++;//注意所有人都得投票
    }
    if(s>m) return 0;
    return 1;
}
int main()
{
    int i,j;
    while(~scanf("%d%d",&n,&m))
    {
        if(n==-1&&m==-1) break;
        int L=1,R=-1;
        for(i=1;i<=n;i++)
        {
            scanf("%d",&num[i]);
            if(num[i]>R) R=num[i];
        }
        while(L<R)
        {
            int mid=(L+R)/2;
            if(!judge(mid))L=mid+1;
            else R=mid;
        }
        printf("%d\n",R);
    }
    return 0;
}
时间: 2024-08-25 11:42:47

hdu4190 简单二分的相关文章

HDU 2119 Matrix 简单二分匹配

行做x集,列做y集,1就给该行该列连一条边,输出最大匹配边即可 #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<vector> #include<set> using namespace std; #define N 105 int lef[N], pn;//lef[v]表示Y集的点v 当前连接的点 , pn为x点集的

poj 3273 Monthly Expence 简单二分

1 /** 2 大意: 有连续的n天,每一天有一定的花费,将其分成m份,每一份占一天或者连续的几天,求这m份中的最大值 3 思路: 二分其最大上限,看在此最大上线,能分成多少份,若大于m份,说明上限过小,需要扩大上限 4 若小于m份,则说明,下限过大,需要缩小上限. 5 **/ 6 #include <iostream> 7 8 using namespace std; 9 int c[100010]; // 记录,每天的花费 10 int main() 11 { 12 int n,m; 13

poj 2785 4 Values whose Sum is 0 (简单二分)

//每列选一个数相加为0的个数 # include <stdio.h> # include <algorithm> # include <string.h> using namespace std; int ab[4010*4010],cd[4010*4010]; int main() { int n,i,k,j,count,a[4010],b[4010],c[4010],d[4010]; while(~scanf("%d",&n)) { f

hdu-4185.loiol_skimming(简单二分匹配模型)

1 /************************************************************************* 2 > File Name: hdu-4185.oil_skimming.cpp 3 > Author: CruelKing 4 > Mail: [email protected] 5 > Created Time: 2019年09月03日 星期二 09时12分12秒 6 本题思路:简单分析过后就可以知道如果一点a被另一个点b匹配

hdu1551 简单二分

题意是给你n跳绳子    分成k段的最大长度          二分枚举长度 #include<stdio.h> #include<string.h> #include<iostream> using namespace std; #define exp 1e-5 double num[11000]; int k,n; int judge(double x) { int s=0; for(int i=1;i<=n;i++) { s+=(int)(num[i]/x)

hdu4004 简单二分+贪心

找到二分的左右值  然后对每一个中值进行判断 #include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> using namespace std; int n,m,L; int num[500010]; int abs(int a) { return a<0?-a:a; } int max(int a,int b) { return a>b?a:b; }

poj2785 简单二分

4 Values whose Sum is 0 Time Limit: 15000MS   Memory Limit: 228000K Total Submissions: 19243   Accepted: 5744 Case Time Limit: 5000MS Description The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute how

Acwing102 最佳牛围栏 (简单二分)

首先:  (1):   这个*1000的操作肯定是为了防止出现double,这样的话都是整数,好操作!!!!!! (2):  这个首先从暴力方向来想,我们要知道这个的值的话,我们的方法好像只有枚举所有大于等于F的区间来进行操作,但是这样的复杂度是O(N^2-F^2),这个可以等效看作是N^2的,只要数据稍微大一点点,这个算法就会被卡掉 (3): 然后这个可以接受的数据范围是Nlog(N)的? (4): 每块地的平均值最大?   那么这个函数肯定是单调递增的,我们可以二分一个值来验证,看看这个值是

简单二分

1 #include <iostream> 2 3 using namespace std; 4 //upper_bound(a, arr + 10, 7) - a; 5 int search(int *a, int l, int r, int key) 6 { 7 int mid; 8 while(l <= r) 9 { 10 mid = (l + r) / 2; 11 if(a[mid] == key) return mid; 12 if(a[mid] < key) l = m