OI explanations of the village sheep

Pleasant Goat and Big Big Wolf - Warehouse Management

Portal
water a group, but also to open the o2

Do not write


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<string>
#include<cstring>
using namespace std;

inline int read() {
    char c = getchar();
    int x = 0, f = 1;
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int n, x;
char s[5];
priority_queue<int,vector<int>,greater<int> > q;
int main()
{
    scanf("%d",&n);
    while(n--)
    {
        scanf("%s",s);
        if(s[0]=='i')
        {
            scanf("%d",&x);
            q.push(x);
        }
        else
        {
            printf("%d\n",q.top());
            q.pop();
        }
    }
    return 0;
}

Pleasant Goat and Big Big Wolf - breaking the code

Portal

This problem of water data is very very water, make a small table on the past, Gugu Gu

But still the thing to say about positive solutions

Just use the number of theorems about the number on the line, saying no one even Baidu?

Portal

Pleasant Goat and Big Big Wolf - trouble gift

That is half the answer ah, probably meaning of the title is not clear, but I wrote a note, ah, is a construction worker can buy more gifts, but not more than construction workers buy a gift, I am not yet written on the subject ( fog)

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<string>
#include<cstring>
using namespace std;

inline int read() {
    char c = getchar();
    int x = 0, f = 1;
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int n,m,a[100005],l,r,mid,s,t;
bool yd;
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        l=max(l,a[i]); r+=a[i]; //最少一个人买一个礼物买完,最多一个人把所有都买下来
    }
    while(l<=r)
    {
        mid=(l+r)/2;
        s=mid-a[1]; t=m; yd=0; //s为当前工人所剩的钱,t为礼物数
        for(int i=2;i<=n;i++)
         if(s>=a[i]) s-=a[i]; //如果可以继续买就继续买
         else if(t>0) s=mid-a[i],t--; //否则还要建筑工人的话,换另一个建筑工人
         else {yd=1; break;} //否则就不能
        if(yd) l=mid+1;
        else r=mid-1;
    }
    printf("%d",l);
    return 0;
}

Guess you like

Origin www.cnblogs.com/pyyyyyy/p/11139913.html