题目传送门

 /*
贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-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的更多相关文章

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

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

  3. 模拟 Codeforces Round #288 (Div. 2) A. Pasha and Pixels

    题目传送门 /* 模拟水题:给定n*m的空白方格,k次涂色,将(x,y)处的涂成黑色,判断第几次能形成2*2的黑色方格,若不能,输出0 很挫的判断四个方向是否OK */ #include <cs ...

  4. 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know

    题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再 ...

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

  6. 模拟 Codeforces Round #203 (Div. 2) C. Bombs

    题目地址:http://codeforces.com/problemset/problem/350/C /* 题意:机器人上下左右走路,把其他的机器人都干掉要几步,好吧我其实没读懂题目, 看着样例猜出 ...

  7. 模拟 Codeforces Round #297 (Div. 2) A. Vitaliy and Pie

    题目传送门 /* 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 题目倒是很长:) */ #include <cstdio> #include <algorithm> ...

  8. 模拟 Codeforces Round #249 (Div. 2) C. Cardiogram

    题目地址:http://codeforces.com/contest/435/problem/C /* 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 模拟题:蛮恶心的,不过也简单 ...

  9. queue+模拟 Codeforces Round #304 (Div. 2) C. Soldier and Cards

    题目传送门 /* 题意:两堆牌,每次拿出上面的牌做比较,大的一方收走两张牌,直到一方没有牌 queue容器:模拟上述过程,当次数达到最大值时判断为-1 */ #include <cstdio&g ...

随机推荐

  1. Hibernate双向一对一对象关系模型映射

    一个员工一辆车:one-to-one 实现一:让汽车表中的外键唯一 create table emp ( eid int primary key auto_increment, ename varch ...

  2. java操作数据库出错

    "无效的列索引"其实是个低级的错误 出错原因:1.sql串的?号数目和提供的变量数目不一致:例如:jdbcTemplate.update(sql, new Object[] {ne ...

  3. eclipse maven新建springMVC项目(原创)

    1.配置eclipse maven 2.新建maven项目 3.新建src/main/java,更新pom <project xmlns="http://maven.apache.or ...

  4. python基础——sorted()函数

    python基础——sorted()函数 排序算法 排序也是在程序中经常用到的算法.无论使用冒泡排序还是快速排序,排序的核心是比较两个元素的大小.如果是数字,我们可以直接比较,但如果是字符串或者两个d ...

  5. 动手动脑及java程序之用消息框进行数的运算

        动手动脑     自信成就人生 动手动脑1 ✿仔细阅读示例: EnumTest.java,运行它,分析运行结果? package demo; public class Test { publi ...

  6. Lattice 的 Framebuffer IP核使用调试笔记之datasheet笔记

    本文由远航路上ing 原创,转载请标明出处. 学习使用以及调试Framebuffer IP 核已经有一段时间了,调试的时候总想记录些东西,可是忙的时候就没有时间来写,只有先找个地方记录下,以后再总结. ...

  7. Scrapy爬取美女图片 (原创)

    有半个月没有更新了,最近确实有点忙.先是华为的比赛,接着实验室又有项目,然后又学习了一些新的知识,所以没有更新文章.为了表达我的歉意,我给大家来一波福利... 今天咱们说的是爬虫框架.之前我使用pyt ...

  8. 服务器知识----IIS架设问题

    1,基本配置,应用程序池,路径等. 2,权限设置  Iuser  IIS_users 只读权限 3,isapi映射  framework安装目录下  运行 aspnet_regiis.exe -i 注 ...

  9. 无废话Android之常见adb指令、电话拨号器、点击事件的4种写法、短信发送器、Android 中各种布局(1)

    1.Android是什么 手机设备的软件栈,包括一个完整的操作系统.中间件.关键的应用程序,底层是linux内核,安全管理.内存管理.进程管理.电源管理.硬件驱动 2.Dalvik VM 和 JVM ...

  10. Extjs ComboBox 动态选中第一项

    有时候我们希望通过Store加载过来的数据,ComboBoxItem能够选择第一条数据作为默认数据,我们可以这么操作: var storeinfo = Ext.create('Ext.data.Sto ...