CodeForces 508C Anya and Ghosts 贪心
做不出题目,只能怪自己不认真
题目:
题意:
给你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 贪心的更多相关文章
- CodeForces 508C Anya and Ghosts
Anya and Ghosts Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u S ...
- CF Anya and Ghosts (贪心)
Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- [CF #288-C] Anya and Ghosts (贪心)
题目链接:http://codeforces.com/contest/508/problem/C 题目大意:给你三个数,m,t,r,代表晚上有m个幽灵,我有无限支蜡烛,每支蜡烛能够亮t秒,房间需要r支 ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
- 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 Gym 100338E Numbers (贪心,实现)
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...
- [Codeforces 1214A]Optimal Currency Exchange(贪心)
[Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...
- 【codeforces 508C】Anya and Ghosts
[题目链接]:http://codeforces.com/contest/508/problem/C [题意] 每秒钟可以点一根蜡烛; 这根蜡烛会燃烧t秒; 然后会有m只鬼来拜访你; 要求在鬼来拜访你 ...
随机推荐
- Mac OS X 下 TAR.GZ 方式安装 MySQL 5.7+
方法: http://www.widlabs.com/article/mac-os-x-install-mysql-57-with-tar-gz mysql下载地址:http://www.mysq ...
- RAW模板开发--入口文件官方规范
每个人都有自己的习惯,为了RAW模板能进一步推广,使RAW模板的开发也更有条理,所以写了这个文章. 规范1格式: <?php /*RAW标记声明-start*/ /*RAW标记声明-over*/ ...
- Vistual Studio 2010 调试无法进断点
系统是2003出现的问题 win8就没事 打sp1 补丁就行
- (Problem 46)Goldbach's other conjecture
It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a ...
- Linux中fork()函数详解(转)
一.fork入门知识 一个进程,包括代码.数据和分配给进程的资源.fork()函数通过系统调用创建一个与原来进程几乎完全相同的进程,也就是两个进程可以做完全相同的事,但如果初始参数或者传入的变量不同, ...
- Windows 8.1 IIS 8.5 远程管理 Windows 2008 R2 IIS 7.0
案例: Windows 8.1 x64 IIS 8.5 inetmgr_amd64_v1.1_en-US.msi Windows 2008 R2 x64 IIS 7.0 在Win8.1 通过IIS ...
- Android系统设置— android.provider.Settings
android.provider.Settings Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS); sta ...
- HDU题解索引
HDU 1000 A + B Problem I/O HDU 1001 Sum Problem 数学 HDU 1002 A + B Problem II 高精度加法 HDU 1003 Maxsu ...
- 自制的七个C,总结的太好了
拿破仑·希尔把它叫做:“自制的七个C”: 1.控制自己的时间(Clock). 时间虽不断流逝,但也可以任人支配.你可以选择时间来工作.游戏.休息.烦恼..虽然客观的环境不一定能任人掌握,但人却可以自己 ...
- 与一线Linux嵌入式开发project师的对话
转:与一线Linux嵌入式开发project师的对话 陈project师一直做Linux的嵌入式开发.作为在开发一线的project师.他对非常多问题的看法可能更切合实际需求,于是,通过邮件.就嵌入式 ...