羊村的OI题解

喜羊羊与灰太狼--仓库管理

传送门
水的一批,还让开o2了

就不写了


#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;
}

喜羊羊与灰太狼--破译密码

传送门

这题数据非常的水非常的水,打个很小的表就过了,咕咕咕

不过还是要说一下正解的嘛

只需要用约数个数定理就行了,话说竟然没人百度?

传送门

喜羊羊与灰太狼--烦恼的礼物

就是二分答案啊,可能是题意不太清楚不过我又写了注意的啊,就是一个建筑工人可以买多个礼物,但是不能多个建筑工人买一个礼物,我不是写在题目上了吗(大雾)

#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;
}

转载于:https://www.cnblogs.com/pyyyyyy/p/11139913.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值