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只鬼来拜访你; 要求在鬼来拜访你 ...
随机推荐
- Android应用开发提高篇(5)-----Camera使用
链接地址:http://www.cnblogs.com/lknlfy/archive/2012/03/06/2382679.html 一.概述 Camera是手机的一个很重要的设备,可以说现在的每一部 ...
- xar安装使用方法
xar是一种扩展的归档格式(eXtensible ARchive format),是一种开源的文件格式.xar文件在Mac OS X 10.5里是用于软件安装程序. ---------------- ...
- pexpect-pxssh-登陆Linux-执行命令
#!/usr/bin/python import pexpect import pxssh try: remote=pxssh.pxssh() hostname=raw_input('hostname ...
- 设置MAVEN_OPTS的推荐方法
运行mvn eclipse:eclipse时,经常会出现因为maven项目过大,导致内存不足java栈溢出的error,需要更改MAVEN启动内存 http://stackoverflow.com/q ...
- WINDOWS操作系统中可以允许最大的线程数(线程栈预留1M空间)(56篇Windows博客值得一看)
WINDOWS操作系统中可以允许最大的线程数 默认情况下,一个线程的栈要预留1M的内存空间 而一个进程中可用的内存空间只有2G,所以理论上一个进程中最多可以开2048个线程 但是内存当然不可能完全拿来 ...
- JAVA FILE or I/O学习 - Desktop本地程序学习
public class DesktopKnow { public void know() { try { Desktop.getDesktop().open(new File("C:\\P ...
- 【蓝桥杯】入门训练 Fibonacci数列
入门训练 Fibonacci数列 时间限制:1.0s 内存限制:256.0MB 问题描述 Fibonacci数列的递推公式为:Fn=Fn-1+Fn-2,其中F1=F2=1. ...
- float存储方式编程验证
取出float在内存中的编码: void printFloatAsBinary(float f){ // 二进制的位数 const int bits = sizeof(f) * 8; // 将floa ...
- 为《31天成为IT服务达人》征求正式名字
写书时.没细想书的名字,仅仅是在想出本能够让同行或未来同行高速入门的书,如今想来还是应正式给他取个名,请朋友们帮忙哟
- Opencv 学习资料集合(更新中。。。)
基础学习笔记之opencv(24):imwrite函数的使用 tornadomeet 2012-12-26 16:36 阅读:13258 评论:9 基础学习笔记之opencv(23):OpenCV坐标 ...