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只鬼来拜访你; 要求在鬼来拜访你 ... 
随机推荐
- MysqlHelp
			using System.Configuration;using MySql.Data: public class MySqlHelp { //链接字符串 private static string ... 
- thinkphp phpexcel导出
			近期做一个项目涉及到商品信息的批量导出与导入,遂记录了下来,框架是tp框架3.2.3(tp5.0性质是一样的,无非是加载方法与所放目录不一样罢了),运用的是phpexcel,闲话不多说,上代码 1.首 ... 
- xar安装使用方法
			xar是一种扩展的归档格式(eXtensible ARchive format),是一种开源的文件格式.xar文件在Mac OS X 10.5里是用于软件安装程序. ---------------- ... 
- selenium 学习笔记 ---新手学习记录(5) 问题总结(java)
			1.今天遇到个奇葩问题,iframe有两个id相同的(如下图) 使用driver.switchTo().frame(“frmLinkPage1”);这个无法使用了. 后来改用driver.switch ... 
- Protel99se教程三:新建PCB文件以及PCB基本设定
			在上一课,我们绘制好SCH原理图后,在这一节课开始,我们介绍,如何将SCH转化成PCB文件,在这一节课,我们主要给大家讲解,如果新建PCB文件以及载入封装图. 第一步:在Documents目录下,新建 ... 
- 手机SIM卡知识大科普
			SIM卡 SIM卡是(Subscriber Identity Module 客户识别模块)的缩写,也称为智能卡.用户身份识别卡,GSM数字移动电话机必须装上此卡方能使用.它在一电脑芯片上存储了数字移动 ... 
- JS实现信息的显示和隐藏
			JS实现信息的显示和隐藏 我们在写注册页面的时候,必填信息是可见的,可选信息是隐藏的,如果用户希望填写,可以单击“详细信息”. 代码如下:<!DOCTYPE html><html&g ... 
- Windows Azure 网站自愈
			编辑人员注释:本文章由 Windows Azure 网站团队的项目经理Apurva Joshi 撰写. 您有多少次在半夜被叫醒去解决一个仅需重新启动网站即可解决的问题?要是可以自动检测一些状况并自动恢 ... 
- swjtu 1962 A+B(模拟)
			题目链接:http://acm.swjtu.edu.cn/JudgeOnline/showproblem?problem_id=1962 问题思路:考察编程基础的问题,涉及到字符串转为数字的问题. 代 ... 
- Visual Studio warning MSB3270:There was a mismatch between the processor architecture of the project being built "MSIL"
			Problem: There was a mismatch between the processor architecture of the project being built "MS ... 
