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 ...
随机推荐
- Flask中的session和cookie以及日志
一.笔记一session: 首先对于session在flask中应该是加密签名的cookie,所以要先生成secret_key app.secret_key = os.environ.get('SEC ...
- Express 框架的安装
从零开始用 Node.js 实现一个微博系统,功能包括路由控制.页面模板.数据库访问.用户注册.登录.用户会话等内容. Express 框架. MVC 设计模式. ejs 模板引擎 MongoDB 数 ...
- SSL安装方法二:Windows Server 2008安装SSL证书(IIS 7.5)
SSL证书CSR和CA证书唯一的区别就在:申请证书中的通用名称,具体还要看具体的项目这里只做参考.可以参考SSL安装方法一 背景:IIS 7.5 一.收到SSL证书 仔细阅读邮件 按步骤进行: 1) ...
- js对字符串进行加密和解密方法!
在做一些微信小程序,或混合 app 的时候,或者是考虑到一些 JS 数据安全的问题.可能会使用到 JS 对用户信息进行缓存. 例如在开发:微信小程序对用户进行加密缓存,开发混合APP对用户信息进行加密 ...
- 使用任意的输入流(InputStream)实例,包括字符串形式的文件路径或者 file:// 的 URL 形式的文件路径来配置
mybatis – MyBatis 3 | 入门 http://www.mybatis.org/mybatis-3/zh/getting-started.html 从 XML 中构建 SqlSessi ...
- TA-Lib中文文档(二):talib安装
安装 使用pip安装 PyPI: $ pip install TA-Lib Or checkout the sources and run setup.py yourself: $ python se ...
- sqlserver如何读写操作windows系统的文件
DECLARE @object int DECLARE @hr int DECLARE @src varchar(255), @desc varchar ...
- socketserver源码解析和协程版socketserver
来,贴上一段代码让你仰慕一下欧socketserver的魅力,看欧怎么完美实现多并发的魅力 client import socket ip_port = ('127.0.0.1',8009) sk = ...
- Http协议中Cookie详细介绍(转)
原文:http://www.169it.com/article/3217120921.html Cookie总是保存在客户端中,按在客户端中的存储位置,可分为内存Cookie和硬盘Cookie.内存C ...
- MySQL的redo log结构和SQL Server的log结构对比
MySQL的redo log结构和SQL Server的log结构对比 innodb 存储引擎 mysql技术内幕 log buffer根据一定规则将内存中的log block刷写到磁盘,这个规则是 ...