Cupcakes Gym
来源:互联网 发布:sql server2012r2下载 编辑:程序博客网 时间:2024/06/05 15:04
题目: 给出n个人, 共有k块蛋糕。
每个人轮流吃蛋糕, 最能吃的货每次吃掉ax个(若不足ax个就全吃光),其他人每次会吃1~ai个。
规定第一个发现蛋糕被吃干净的人打扫卫生。人们想坑最能吃的货,问你能否成功让最能吃的货打扫卫生。
这个题在比赛时我倒是有点思路, 就是想了一下 其他人只吃一个 和 其他人也都吃a[i]个。这便是每次的范围。
当时没想着实现。。。 没想到确实有人做到了= =唉
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#define inf 0x3f3f3f#define ll long long#define ms(x) memset(x, 0, sizeof(x))using namespace std;int main(){ int n, f; ll k; ll a[100005]; ll sum[100005]; //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); scanf("%d%lld",&n,&k); ms(a); ms(sum); int ma = 0,t=0; for(int i=1;i<=n;i++) { scanf("%lld",&a[i]); sum[i] = sum[i-1] + a[i]; if(ma<a[i]) { ma = a[t = i]; } } ll x = n+ma-1; // 其他人吃1个,吃货吃a[t]个 ll y = sum[n]; // 每个人都吃a[i]个 x,y就是每一轮人们吃的最少和最多的量 if(k == 0) { if(t == 1) f=1; else f=0; } else { f=0; int i =0; //i从0开始, 因为第一轮不会都吃到蛋糕嘛 while(1) { if((ll)i*x + t-1 > k) break; if((ll)i*y + sum[t-1]>=k) { f=1; break; } i++; } } if(f) printf("YES\n"); else printf("KEK\n"); return 0;}
阅读全文
0 0
- Cupcakes Gym
- 【思维】Cupcakes Gym
- Apple Cupcakes
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- 121. Best Time to Buy and Sell Stock
- python
- ~骑士的游历~
- 百度集成开发与发布版SHA1获取
- http解析过程
- Cupcakes Gym
- hdu2202 凸包+旋转卡壳
- 集合嵌套if语句的时候会有多余的输出解决办法
- 输入挂终极升级版
- Top K Frequent Elements问题及解法
- 待定
- vue 列表渲染双向绑定
- 【字符串处理】HDU6144 Arithmetic of Bomb
- 集训第二十五天(2017/8/24):树状数组&团队赛