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. scss的安装使用

    Ruby的安装 如果是Window系统,请打开:http://rubyinstaller.org/downloads/ ,下载当前稳定版本的exe文件.界面如下所示: Step(2): 接下来,在系统 ...

  2. react 侧栏二级菜单组件

    侧边栏菜单组件 component 下新建menu文件,menu下建index.jsx和subitem.jsx index.jsx import React, { Component } from ' ...

  3. 【MySQL】为什么不要问我DB极限QPS/TPS

    为什么不要问我DB极限QPS/TPS 背景 相信很多开发都会有这个疑问,DB到底可以支撑多大的业务量,如何去评估?对于这个很专业的问题,DBA也没有办法直接告诉你,更多的都是靠经验提供一个看似靠谱的结 ...

  4. sqlserver如何读写操作windows系统的文件

    DECLARE   @object   int     DECLARE   @hr   int     DECLARE   @src   varchar(255),   @desc   varchar ...

  5. 利用GridView实现单选效果

    1.实现如图所示的单选效果 由于Android提供的单选按钮radiobutton只能单行或单列显示,且样式并不美观,故可用GridView进行改造,实现单选效果,而要实现这样的效果重点就在GridV ...

  6. python获取当天日期进行格式转换

    # Python Library import time def getToday(format=3): """返回今天的日期字串""" # ...

  7. docker搭建oracle 11.2.0.3.0

    dockerfile 如下: FROM oraclelinux:-slim ARG ORACLE_BASE=/opt/oracle ARG ORACLE_HOME=/opt/oracle/produc ...

  8. Openstack(十三)部署管理服务horizon

    13.1horizon介绍 horizon是openstack的管理其他组件的图形显示和操作界面,通过API和其他服务进行通讯,如镜像服务.计算服务和网络服务等结合使用,horizon基于python ...

  9. ubuntu16.04 安装指定版本Node,升级npm到指定版本

    一.安装配置Node 1.下载(64位系统) wget https://nodejs.org/download/release/v10.1.0/node-v10.1.0-linux-x64.tar.g ...

  10. leetcode 数据库题解

    184. Department Highest Salary 题意: The Employee table holds all employees. Every employee has an Id, ...