贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
/*
贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支),
num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数,
然后接下来的t秒需要的蜡烛都燃烧着,超过t秒,每减少一秒灭一支蜡烛,好!!!
详细解释:http://blog.csdn.net/kalilili/article/details/43412385
*/
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
using namespace std; const int MAXN = 1e3 + ;
const int MAXG = + ;
const int INF = 0x3f3f3f3f;
int g[MAXG];
int num[MAXN]; int main(void) //Codeforces Round #288 (Div. 2) C. Anya and Ghosts
{
#ifndef ONLINE_JUDGE
freopen ("C.in", "r", stdin);
#endif int m, t, r; scanf ("%d%d%d", &m, &t, &r);
for (int i=; i<=m; ++i)
scanf ("%d", &g[i]); if (t < r)
{
puts ("-1"); return ;
}
int ans = ;
for (int i=; i<=m; ++i)
{
if (num[g[i]] < r)
{
int tmp = r - num[g[i]];
ans += tmp;
for (int j=g[i]+; j<=g[i]-tmp+t; ++j) num[j] += tmp;
for (int j=g[i]-tmp+t+; j<=g[i]+t-; ++j) num[j] += (--tmp);
}
} printf ("%d\n", ans); return ;
}
贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts的更多相关文章
- Codeforces Round #288 (Div. 2) C. Anya and Ghosts 模拟 贪心
C. Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #288 (Div. 2) C. Anya and Ghosts 模拟
C. Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 模拟 Codeforces Round #288 (Div. 2) A. Pasha and Pixels
题目传送门 /* 模拟水题:给定n*m的空白方格,k次涂色,将(x,y)处的涂成黑色,判断第几次能形成2*2的黑色方格,若不能,输出0 很挫的判断四个方向是否OK */ #include <cs ...
- 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know
题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再 ...
- Codeforces Round #297 (Div. 2)E. Anya and Cubes 折半搜索
Codeforces Round #297 (Div. 2)E. Anya and Cubes Time Limit: 2 Sec Memory Limit: 512 MBSubmit: xxx ...
- 模拟 Codeforces Round #203 (Div. 2) C. Bombs
题目地址:http://codeforces.com/problemset/problem/350/C /* 题意:机器人上下左右走路,把其他的机器人都干掉要几步,好吧我其实没读懂题目, 看着样例猜出 ...
- 模拟 Codeforces Round #297 (Div. 2) A. Vitaliy and Pie
题目传送门 /* 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 题目倒是很长:) */ #include <cstdio> #include <algorithm> ...
- 模拟 Codeforces Round #249 (Div. 2) C. Cardiogram
题目地址:http://codeforces.com/contest/435/problem/C /* 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 模拟题:蛮恶心的,不过也简单 ...
- queue+模拟 Codeforces Round #304 (Div. 2) C. Soldier and Cards
题目传送门 /* 题意:两堆牌,每次拿出上面的牌做比较,大的一方收走两张牌,直到一方没有牌 queue容器:模拟上述过程,当次数达到最大值时判断为-1 */ #include <cstdio&g ...
随机推荐
- 安装Birt方法
安装BIRT 方法: 博客地址:http://www.mamicode.com/info-detail-850588.html 注意:在 Install new Software 中输入地址:http ...
- XMPP框架下微信项目总结(4)重新连接服务器
xmpp 很多功能是面向模块开发的 例如电子名片 无须自己去写请求的代码XMPP(文件)->Extension(存放的是各个模块)->Reconnect(自动连接模块) ...
- self和parent的用法
总结 self , parent 的用法 只能用在类的内部 self 本类 (不要理解成本对象) parent 父类 在引入自身的静态属性/静态方法 以及父类的方法时 ...
- 并发中的Native方法,CAS操作与ABA问题
Native方法,Unsafe与CAS操作 >>JNI和Native方法 Java中,通过JNI(Java Native Interface,java本地接口)来实现本地化,访问操作系统底 ...
- 【翻译二十】-java线程池
Thread Pools Most of the executor implementations in java.util.concurrent use thread pools, which co ...
- Counterfeit Dollar -----判断12枚钱币中的一个假币
Counterfeit Dollar Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u ...
- oracle JOB学习(一)---基础
oracle job简介 下面文章来自网友(格式稍加整理) 主要的使用情景 定时在后台执行相关操作:如每天晚上0点将一张表的数据保存到另一张表中,2:定时备份数据库等 熟化说万事开头难,这 ...
- TortoiseSVN常用批处理命令 分类: C# 2014-08-09 11:31 648人阅读 评论(1) 收藏
TortoiseSVN作为源代码管理软件,估计用过的都会说好,在Windows下,配合批处理命令,往往可以事半功倍,整理了下常用的批处理命令: (将下面的内容修改后,保存为*.bat文件执行即可) : ...
- js 控制展开折叠 div html dom
js 控制展开折叠 div html dom <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ...
- 1-01Sql Sever 2008的安装
Sql Sever 2008对计算机的配置要求: 1:处理器:最低1.4Ghz的处理器,建议使用2.0GHz或更高的处理器 . 2:内存:最小512MB, 建议使用1GB或更高的处理器. 3:磁盘容 ...