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 ...
随机推荐
- 在linux下安装Avria(小红伞)
1.下载AntiVir PersonalEdition Classic for linux http://www.free-av.com/ 2.解压: tar zxvf antivir.tar.gz ...
- 微信小程序 --- 获取网络状态
获取网络状态:wx.getNetworkType btnclick:function(){ wx.getNetworkType({ success:function(res){ console.log ...
- SpringBoot系列教程起步
本篇学习目标 Spring Boot是什么? 构建Spring Boot应用程序 三分钟开发SpringBoot应用程序 本章源码下载 Spring Boot是什么? spring Boot是由Piv ...
- 【JavaScript算法】---快速排序法
一.快速排序法概念 我们将一个杂乱无章的数组进行一个快速排序,可以先从一个数组中取一个中间值,将一个数组一分为2,左边的数组跟中间值进行比较,小的放在左边,大的放在右边.比较完毕后再次取中间值,再次比 ...
- 03Del.ashx(删除班级)
03Del.ashx 数据库里定义个BOOL型,TRUE表示正常FALSE表示删除 using System; using System.Collections.Generic; using Syst ...
- WebConfig配置详解大全
<?xml version="1.0"?> <!--注意: 除了手动编辑此文件以外,您还可以使用 Web 管理工具来配置应用程序的设置.可以使用 Visual S ...
- explain 分析 聚合统计语句的性能
EXPLAIN SELECT COUNT(1) FROM question; id select_type table partitions type possible_keys key key_le ...
- nginx中获取真实ip(转)
原文:http://blog.csdn.net/a936676463/article/details/8961504 server { listen 80; server_name lo ...
- Jquery EasyUI插件
属性 属性是定义在 jQuery.fn.{plugin}.defaults.比如,dialog 的属性是定义在 jQuery.fn.dialog.defaults. 事件 事件(回调函数)也是定义在 ...
- C#检查文件是否被占用
第一种方法: using System.IO; using System.Runtime.InteropServices; [DllImport("kernel32.dll")] ...