羊村的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
",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