hdu 4190

二分求箱子中的票数  然后判是否满足条件     主要为了纪念一下用优先队列9000ms水过

#include<cstdio>
#include<climits>
#include<algorithm>
using namespace std;
int n,m,a[600000];
bool check(int mid)
{
    int cnt = 0;
    for(int i = 0; i < n; i++)
        cnt += a[i]/mid+(a[i]%mid>0);
    return cnt <= m;
}
int solve(int x,int y)
{
    if(x == y) return x;
    int mid = x+(y-x)/2;
    if(check(mid))
        return solve(x, mid);
    else
        return solve(mid+1, y);
}
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF && ((n+1)||(m+1)))
    {
        int big = 0;
        int small = INT_MAX;
        for(int i = 0; i < n; i++)
            scanf("%d",&a[i]),big=max(a[i],big),small=min(a[i],small);
        sort(a,a+n);
        printf("%d\n",solve(1,big));
    }
    return 0;
}

#include <iostream>
#include <cmath>
#include <fstream>
#include <cstring>
#include <queue>
using namespace std;
struct node
{
    int a,b;
    node(int i, int j)
    {
        a = i, b = j;
    }
    bool operator < (const node &p) const
    {
        return ((double)a/b) < ((double)p.a/p.b);
    }
};

int main()
{
    //freopen("in.txt","r",stdin);
    int n,k;
    while(scanf("%d%d",&n,&k) == 2)
    {
        if(n == -1 && k == -1)
            break;
        k -= n;
        priority_queue<node> Q;
        for(int i = 0; i < n; i++)
        {
            int x;
            scanf("%d",&x);
            Q.push(node(x, 1));
        }
//        cout<<Q.top().a<<endl;
        while(k--)
        {
            node u = Q.top();
            Q.pop();
            Q.push(node(u.a, u.b+1));
        }
        printf("%d\n",(int)ceil((double)Q.top().a/Q.top().b));
    }
    return 0;
}


posted @ 2013-09-04 13:37  xlc2845  阅读(118)  评论(0)    收藏  举报