做不出题目,只能怪自己不认真


题目:

Click here

题意:

给你3个数m,t,r分别表示鬼的数量,每只蜡烛持续燃烧的时间,每个鬼来时要至少亮着的蜡烛数量,接下来m个数分别表示每个鬼来的时间点(増序)。输出至少要点多少只蜡烛,不能完成输出-1。注意t时刻点蜡烛,t+1时刻才管用。并且一个时间点只能点一支蜡烛

分析:

很明显的贪心,就尽可能晚的点蜡烛,能少点就少点。

代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; const int M = 3e2+5; int m, t, r;
int w[M]; //鬼出现的时间
int vis[M]; //表示i时刻亮着的蜡烛的数量
int main() {
while( ~scanf("%d%d%d", &m, &t, &r ) ) {
for( int i=0; i<m; i++ )
scanf("%d", w+i );
if( t < r ) { //这种情况就是一个时间点最多t个蜡烛亮着,但却需要至少r个蜡烛
printf("-1\n");
continue;
}
memset( vis, 0, sizeof(vis) );
int cnt = 0;
for( int i=0; i<m; i++ ) {
int c = r - vis[w[i]];
if( c > 0 ) {
cnt += c;
for( int j=0; j<c; j++ ) {
for( int k=w[i]-j; k<w[i]-j+t;k++ ) {
if( k<0 || k>300 )
continue;
vis[k]++;
}
}
}
}
printf("%d\n", cnt );
}
return 0;
}

CodeForces 508C Anya and Ghosts 贪心的更多相关文章

  1. CodeForces 508C Anya and Ghosts

     Anya and Ghosts Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u S ...

  2. CF Anya and Ghosts (贪心)

    Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  3. [CF #288-C] Anya and Ghosts (贪心)

    题目链接:http://codeforces.com/contest/508/problem/C 题目大意:给你三个数,m,t,r,代表晚上有m个幽灵,我有无限支蜡烛,每支蜡烛能够亮t秒,房间需要r支 ...

  4. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

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

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

  7. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  8. [Codeforces 1214A]Optimal Currency Exchange(贪心)

    [Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...

  9. 【codeforces 508C】Anya and Ghosts

    [题目链接]:http://codeforces.com/contest/508/problem/C [题意] 每秒钟可以点一根蜡烛; 这根蜡烛会燃烧t秒; 然后会有m只鬼来拜访你; 要求在鬼来拜访你 ...

随机推荐

  1. Trie implementation

    在学习 Aho - Corasick Automation Algorithm 之前,先学习一下,Trie 的实现过程: The name trie comes from its use for re ...

  2. mac上搭建svn服务器

    1.terminal 执行svnadmin create 库地址/库名,生成的即为svn库根地址. 2.修改对应目录下conf/svnserve.conf文件: anon-access = read ...

  3. sqlserver 只有函数和扩展存储过程才能从函数内部执行

    一个SQLServer的自定义函数中调用一个自定义的存储过程,执行此函数后发出如下提示:“只有函数和扩展存储过程才能从函数内部执行". 原因:函数只能使用简单的sql语句,逻辑控制语句,复杂 ...

  4. C-重定向

    说实话,第一次接触重定向这一个概念,感觉是那么的神奇简洁不可思议…………………… freopen() 本来应该是打开的是文件指针,但是分配了指针,使她(亲切)指向了标准输入.输出.错误流. 用 法: ...

  5. IOS 学习笔记(1) 视图UIViewController

    1.UIViewController *newController=[[UIViewController alloc] initWithNibName:@"XXX" bundle: ...

  6. 将默认首页设置成index.do的方法

    变态欺骗法,今天csdn一个前辈的,学习了,公司服务器是weblogic的,也可以欺骗. 但是我又非常迫切.非常盼望.非常渴望使用index.do做首页,怎么办? Tomcat中用一段注释: When ...

  7. jQuery.merge 源码阅读

    jQuery.merge(first,second) 概述 合并两个数组 返回的结果会修改第一个数组的内容——第一个数组的元素后面跟着第二个数组的元素. 参数 first:第一个待处理数组,会改变其中 ...

  8. hdoj 1269 迷宫城堡(强连通分量)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1269 思路分析:该问题要求判断是否每两个房间都可以相互到达,即求该有向图中的所有点是否只构成一个强连通 ...

  9. One Person Game(扩展欧几里德求最小步数)

    One Person Game Time Limit: 2 Seconds      Memory Limit: 65536 KB There is an interesting and simple ...

  10. tomcat的webappclassloader中一个奇怪的异常信息

    假设一个应用抛出大量的Class not found信息,一般你会怀疑包冲突.但是tomcat的webappclassloader却有这种问题: 假设一个应用公布出现故障, webappclasslo ...