【题目链接】:http://codeforces.com/contest/508/problem/C

【题意】



每秒钟可以点一根蜡烛;

这根蜡烛会燃烧t秒;

然后会有m只鬼来拜访你;

要求在鬼来拜访你的时候,至少有r根蜡烛是处于燃烧状态的;

然后你能在任意一个时刻点蜡烛;

问你最少需要点多少根蜡烛;

【题解】



对每只鬼进行考虑;

则必须有r跟蜡烛能够”控制它”

在什么地方控制呢?

一定是离它最近的地方;

因为这样;

能够让这根蜡烛的使用范围达到最大;

尽可能地覆盖到更多的鬼;

这样那些鬼需要的蜡烛就能变少;

就按照这个贪心策略搞就好;



【Number Of WA】



0



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) cin >> x
#define pri(x) cout << x
#define ms(x,y) memset(x,y,sizeof x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,0,-1,0,-1,-1,1,1};
const int dy[9] = {0,0,-1,0,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int M = 3e2+100; struct abc
{
int x,need;
}; int m,t,r,ans = 0;
abc a[M];
map <int,int> dic; int main()
{
//freopen("D:\\rush.txt","r",stdin);
ios::sync_with_stdio(false);
cin >> m >> t >> r;
rep1(i,1,m)
cin >> a[i].x,a[i].need = r;
rep1(i,1,m)
if (a[i].need>0)
{
int j = a[i].x-1;
while (a[i].need)
{
while (dic[j]==1) j--;
//dic[j]>0
if (j+t<a[i].x) return cout <<-1<<endl,0;
dic[j] = 1;
ans++;
rep1(k,i+1,m)
if (j+t>=a[k].x)
a[k].need--;
a[i].need--;
}
}
cout << ans << endl;
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

【codeforces 508C】Anya and Ghosts的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  3. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  4. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  5. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  6. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  7. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  8. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

  9. 【codeforces 515D】Drazil and Tiles

    [题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...

随机推荐

  1. Visual Studio Code配置GitHub(Win7环境)

    一.软件环境说明(演示环境) 1.操作系统:Windows7旗舰版(64bit) 2.Visual Studio Code版本:1.32.3 3.Git版本:2.21.0.windows.1 二.软件 ...

  2. 调取easyui -windows 返回值问题

    //-------------------------------------------------------------------------------------------------- ...

  3. HDU 3785 找寻大富翁

    2019-06-06 08:30:03 坚持!!! 做这些水题,都觉得心累,特别是HDU的题,我PE了3发

  4. C/C++常用头文件 以及简单应用介绍

    C/C++头文件一览 C #include <assert.h> //设定插入点#include <ctype.h> //字符处理#include <errno.h> ...

  5. scrapy框架简介和基础应用(python爬虫)

    一.什么是scrapy? scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架,非常出名,非常强悍,所谓的框架就是一个已经被集成了各种功能(高性能异步下载,队列,分布式,持久化等)的具有 ...

  6. android webview 简单应用

    一直没有用过webView 在网上找了一个小例子,主要实现以下功能: 1.当webview加载网页的时候在标题栏上显示加载进度 2.隐藏webkit浏览器的地址栏 3.设置程序的标题为网页的标题 4. ...

  7. android 二维码 扫描,生成,竖屏

    最近公司有用到二维码,生成,扫描,所以学习了一下,和大家分享: demo 见下面链接,已经改成竖屏: http://download.csdn.net/detail/q610098308/868101 ...

  8. No operations allowed after connection closed--转

    https://www.jianshu.com/p/1626d41572f2 Spring boot的单数据源配置比较简单,只需要在application.properties配置相关的jdbc连接的 ...

  9. 微信自定义分享功能实现Tips

    以MVC为例 前台js通过.post()方法传给后台特定Controller当前页面的url,后台获取后,进行处理: 1.获取access_token:https://mp.weixin.qq.com ...

  10. html5——渐变

    线性渐变 <style> div { width: 700px; height: 100px; /*方向:从右向左*/ /*起始颜色:黄色*/ /*终止颜色:绿色*/ background ...