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只鬼来拜访你; 要求在鬼来拜访你 ...
随机推荐
- HDU1712-ACboy needs your help
描述: ACboy has N courses this term, and he plans to spend at most M days on study.Of course,the profi ...
- select标签操作大全
http://blog.csdn.net/hhhh2012/article/details/8610336
- 加密PHP文件的方式,目测这样可以写个DLL来加密了
<?php function encode_file_contents($filename) { $type=strtolower(substr(strrchr($filename,'.'),1 ...
- python自学笔记(七)排序与多级排序
一.sorted内置方法 a = [1,2,3,4] 从大到小(翻转) a = sorted(a,reverse = True) #生成新对象,不会原地修改,需要重新赋值 print a --> ...
- RFID电子标签的二次注塑封装
生活当中,RFID电子标签具有明显的优势,随着RFID电子标签成本的降低.读写距离的提高.标签存储容量增大及处理时间缩短的发展趋势,R F I D电子标签的应用将会越来越广泛. RFID电子标签的应用 ...
- linux 的 ping 原理
ping命令的工作原理是: ping命令是用来查看网络上另一个主机系统的网络连接是否正常的一个工具. 他向网络上的另一个主机系统发送ICMP报文,如果指定系统得到了报文,它将把报文原样传回给发送者,这 ...
- WEB和APP谁是互联网未来
据中国多家权威报告显示,作为多年专业化互联网公司炎帝网络科技综合评估预测,预计2016年全球互联网设备将达到100亿部.如果届时全球人口达到73亿,意味着平均每人将有1.4部设备.智能交通将增长50倍 ...
- java.lang.class.getResource
静态块,在项目启动的时候就执行,是主动执行的. 静态方法, 是被动执行的,需要被调用才执行. static{ try { String path = Conf ...
- java学习之jdbc的封装
jdbc是连接数据库必不可少的工具,但每次连接都要重新写一遍太麻烦了,也不利于代码的可读性,这里做一个工具类进行封装. package com.gh; import java.sql.Connecti ...
- Oracle PL/SQL 游标
在PL/SQL块中执行SELECT.INSERT.DELETE和UPDATE语句时,ORACLE会在内存中为其分配上下文区(Context Area),即缓冲区.游标是指向该区的一个指针,或是命名一个 ...