L-鸡尾酒买罐子 贪心枚举 假二分

https://ac.nowcoder.com/acm/contest/321/L
n虽然1e9 但是k<=300个罐子 买m个
a[i]<=1000 枚举钱数3e5
k=3个罐子
7 4 2
n=10

二分的话 钱数增 个数不一定增
n=10 2
n=9 2
n=8 1
n=7 1
n=6 2

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
const ll mod=1e9+7;
const int INF=0x3f3f3f3f;
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define pb push_back
ll T;
ll n,m,k,a[maxn],cnt;
//枚举钱数 k=300个1000 最大3e5 钱数不枚举0 虽然有0 
int main(){		
	IO;
	cin>>n>>m>>k;
	for(int i=1;i<=k;i++){
		cin>>a[i];
	} 
	ll num=min(n,k*1000);
	for(int i=1;i<=num;i++){	//枚举钱数 
		ll q=i;
		cnt=0;
		for(int j=1;j<=k;j++){
			if(q>=a[j]){
				cnt++;
				q-=a[j];
			}
			if(q==0)
				break;
			
			
		}
		if(cnt>=m)
		{
			return cout<<i<<endl,0;
		}
	}
	//到最大钱数都买不了m个罐子 钱数较小 罐子比较贵 
	cout<<"poor chicken tail wine!"<<endl;
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
const ll mod=1e9+7;
const int INF=0x3f3f3f3f;
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define pb push_back
ll T;
ll n,m,k,a[maxn],cnt;
//枚举钱数 k=300个1000 最大3e5 钱数不枚举0 虽然有0 
bool check(ll x){
	ll cnt=0;
	for(int i=1;i<=k;i++){
		if(x>=a[i]){
			cnt++;
			x-=a[i];
		}
		if(cnt>=m || x==0)	break;
	}
	return cnt>=m;
}
int main(){		
	IO;
	cin>>n>>m>>k;
	for(int i=1;i<=k;i++){
		cin>>a[i];
	} 
	ll num=min(n,k*1000); 
	for(int i=1;i<=num;i++){
		if(check(i)){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<"poor chicken tail wine!"<<endl;
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值