Gym 101243E Cupcakes
http://codeforces.com/gym/101243/attachments
题意:
有n个人,桌子上有k的蛋糕,每个人都有一个值val,表示每次轮到他吃蛋糕时,他可以吃1~val的蛋糕量。在这n个人当中,val最大的人是最贪婪的,他每次都会固定的吃val蛋糕。现在一个一个排好队吃蛋糕,如果轮到谁吃蛋糕时已经没有蛋糕了,那么这个人就要打扫卫生,现在要判断是否能让最贪婪的人去打扫卫生。
思路:
先找出最贪婪的那个人,计算出他左边的人一轮下来所要吃的最少的蛋糕量l_min和最多的蛋糕了l_max,另外还要计算出一轮下来除贪婪人外其余人所要吃的最少的蛋糕了和最多的蛋糕量。
如果l_min<=k<=l_max,那么左边的人肯定能在轮到贪婪的人吃时正好吃完蛋糕。
如果不能的话,那么蛋糕就要被贪婪的人吃掉点,接下来我们加上一轮下来其余人所要吃的最少的蛋糕和最多的蛋糕,重复上述步骤判断。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5+; int n, k;
ll a[maxn]; int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
//freopen("input.txt","r",stdin);
while(~scanf("%d%d",&n,&k))
{
ll MAX=;
for(int i=;i<=n;i++)
{
scanf("%lld",&a[i]);
MAX=max(MAX,a[i]);
} ll l_min=, l_max=;
ll round_min=, round_max=;
bool flag=true; for(int i=;i<=n;i++)
{
if(a[i]==MAX) {flag=false;continue;}
if(flag)
{
l_min++;
l_max+=a[i];
}
round_min++;
round_max+=a[i];
} flag=false;
while(k>=)
{
if(k>=l_min && k<=l_max)
{
puts("YES");
flag=true;
break;
}
else
{
k-=MAX;
l_min+=round_min;
l_max+=round_max;
} }
if(!flag) puts("KEK");
}
return ;
}
Gym 101243E Cupcakes的更多相关文章
- ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力
Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS Memory Limit:65536KB 64bit IO Fo ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Gym 101047B Renzo and the palindromic decoration Time Limit:2000MS Memory Limit:65536KB 64 ...
- Gym 101102J---Divisible Numbers(反推技巧题)
题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...
- Gym 100917J---Judgement(01背包+bitset)
题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...
- Gym 100917J---dir -C(RMQ--ST)
题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...
- Gym 101102D---Rectangles(单调栈)
题目链接 http://codeforces.com/gym/101102/problem/D problem description Given an R×C grid with each cel ...
- Gym 101102C---Bored Judge(区间最大值)
题目链接 http://codeforces.com/gym/101102/problem/C problem description Judge Bahosain was bored at ACM ...
随机推荐
- SNMP信息泄露漏洞
SNMP协议简介 名称:SNMP(Simple Network Management Protocol)简单网络管理协议 端口:161 协议:UDP 用途:SNMP代理者以变量呈现管理资料.管理系统透 ...
- Linux显示不了中文
原文:https://www.cnblogs.com/hooly/p/8615384.html 版权所有:归属原文作者!!! 查看当前系统默认采用的字符集: # locale 在RedHat/C ...
- 【BZOJ4922】[Lydsy六月月赛]Karp-de-Chant Number 贪心+动态规划
[BZOJ4922][Lydsy六月月赛]Karp-de-Chant Number Description 卡常数被称为计算机算法竞赛之中最神奇的一类数字,主要特点集中于令人捉摸不透,有时候会让水平很 ...
- iPad - 开发(Universal Applications)
一.iPad 1.判断是否在iPad上 BOOL iPad = ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdi ...
- R载入需要的程辑包:rJava Error
> library(xlsx) 载入需要的程辑包:rJava Error : loadNamespace()里算'rJava'时.onLoad失败了,详细内容: 调用: inDL(x, as.l ...
- 求全局最小割(SW算法)
hdu3002 King of Destruction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- V2EX的RSS订阅地址
1.全站RSS输出: https://www.v2ex.com/index.xml 2.单独节点RSS输出: http://www.v2ex.com/feed/{节点名}.xml 以shadowso ...
- 快速定位oracle故障-恩墨
首先我们要明白一点,所谓的故障,意味着相对来讲比较严重.也就是可能比不同的问题要严重一些,比如锁等待. 要能够快速的定位和解决问题,恢复业务正常:首先我们需要了解Oracle的一些常见的故障有哪些. ...
- 【ArcGIS for SivlerLight api(3)】基础图层增删改查
1.基础底图通常使用TiledLayer或者ArcGISDynamicLayer. 本质上都是在本地加载栅格图片.后台生成策略不同而已.从Vs2010的控件栏上拖过来的Map控件默认添加的底图是Esr ...
- Spring Boot - Building RESTful Web Services
Spring Boot Building RESTful Web Services https://www.tutorialspoint.com/spring_boot/spring_boot_bui ...