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的更多相关文章

  1. 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 ...

  2. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  3. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  4. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  5. Gym 101102J---Divisible Numbers(反推技巧题)

    题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...

  6. Gym 100917J---Judgement(01背包+bitset)

    题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...

  7. Gym 100917J---dir -C(RMQ--ST)

    题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...

  8. Gym 101102D---Rectangles(单调栈)

    题目链接 http://codeforces.com/gym/101102/problem/D problem  description Given an R×C grid with each cel ...

  9. Gym 101102C---Bored Judge(区间最大值)

    题目链接 http://codeforces.com/gym/101102/problem/C problem description Judge Bahosain was bored at ACM ...

随机推荐

  1. ShowDoc 搭建 (未成功....)

    官方教程:https://www.showdoc.cc/help?page_id=13732 下载了showdoc,服务器映射本地磁盘的时候,服务器用户名和密码忘了... 远程服务器用户名和密码修改 ...

  2. 【BZOJ4236】JOIOJI STL

    [BZOJ4236]JOIOJI Description JOIOJI桑是JOI君的叔叔.“JOIOJI”这个名字是由“J.O.I”三个字母各两个构成的. 最近,JOIOJI桑有了一个孩子.JOIOJ ...

  3. android通过数组,流播放声音的方法,音频实时传输

    AudioRecord和AudioTrack类是Android获取和播放音频流的重要类,放置在android.media包中.与该包中 的MediaRecorder和MediaPlayer类不同,Au ...

  4. Android Thread Handler UIHandler demos

    extends:http://blog.csdn.net/superjunjin/article/details/7540064 序效果:为了显示如何用message传值的简单例子 例1,点击按钮,持 ...

  5. SSH电力项目四-显示首页

    1.登录页面: 将上一节中的页面放到/WEB-INF/page/目录下,需要登录后才能访问该页面: 对应页面:/WEB-INF/page/menu/home.jsp <%@ page langu ...

  6. UNIX的插头问题

    UNIX的插头问题 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 你负责为联合国互联网执行组织(UNIX)的周年会议布置会议室. ...

  7. Hibernate--快速上手

    一.初识 Hibernate 经典的软件应用体系结构有三层:表示层(提供了与用户交互的接口,实现用户操作界面,展示用户需要的数据).业务逻辑层(完成业务流程,处理表示层提交的数据请求,并将要保存的数据 ...

  8. python tensorflow keras

    pip install tensorflow pip install keras pip install theano http://www.open-open.com/lib/view/open14 ...

  9. Python开发【数据结构】:算法(二)

    堆排序 1.—树与二叉树简介 树是一种数据结构 比如:目录结构 树是一种可以递归定义的数据结构 树是由n个节点组成的集合: 如果n=0,那这是一棵空树: 如果n>0,那存在1个节点作为树的根节点 ...

  10. UML Diagrams Using Graphviz Dot

    Introduction Background This article is about using the dot tool from the Graphviz package to automa ...