贪心+模拟 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 ...
随机推荐
- SQLServer 批量插入数据的两种方法
SQLServer 批量插入数据的两种方法-发布:dxy 字体:[增加 减小] 类型:转载 在SQL Server 中插入一条数据使用Insert语句,但是如果想要批量插入一堆数据的话,循环使用Ins ...
- TCP/IP五层模型
(2)TCP/IP五层模型的协议 应用层 传输层 网络层 数据链路层 物理层 物理层:中继器.集线器.还有我们通常说的双绞线也工作在物理层 数据链路层:网桥(现已很少使用).以太网交换机(二层 ...
- php 分页查询
get方法 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...
- samba 报错
[root@GitLab data_nfs]# smbclient //localhost/public WARNING: The security=share option is deprecate ...
- android 屏幕旋转
转自:http://blog.csdn.net/oyzhizhong/article/details/8131799 屏是LANDSCAPE的,要让它默认显示为PORTRAIT. 1.kernel里要 ...
- vim: vs sp 调整窗口高度和宽度
转自:http://www.cnblogs.com/xuechao/archive/2011/03/29/1999292.html vim多窗口有时候需要调整默认的窗口宽度和高度,可以用如下命令配合使 ...
- Delphi中的基础数据类型
参考http://www.cnblogs.com/del/archive/2007/12/04/982167.html 在学习之初,在这么多的数据类型中,最好记住这五种标准数据类型(整型.实型.字符型 ...
- ytu 1061: 从三个数中找出最大的数(水题,模板函数练习 + 宏定义练习)
1061: 从三个数中找出最大的数 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 154 Solved: 124[Submit][Status][We ...
- android 入门-库的生成jar 和引用jar
开发环境 1.eclipse 2.android studio 步骤 1.在eclipse 生成 jar包 2.在android studio 引用 jar包 实现步骤 1.在eclipse 创建一个 ...
- WPF线程(Step1)——Dispatcher
使用WPF开发时经常会遇上自己建立的线程需要更新界面UI内容,从而导致的跨线程问题. 异常内容: 异常类型:System.InvalidOperationException 异常描述: "S ...