【题目链接】: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. unique(V.begin(),V.end())

    unique(V.begin(),V.end()) 重排容器算法:sort,unique unique  返回指向不重复区域之后一个位置的迭代器 ///删除vstr中重复的元素 void delete ...

  2. bzoj1997 [Hnoi2010]Planar——2-SAT

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1997 神奇的经典2-SAT问题! 对于两个相交的区间,只能一里一外连边,所以可以进行2-SA ...

  3. Spark SQL读parquet文件及保存

    import org.apache.spark.{SparkConf, SparkContext} import org.apache.spark.sql.{Row, SparkSession} im ...

  4. Mysql 数据库编码问题

    数据库建表后,插入数据,如果数据位汉子,将提示错误:“incorrect string value....”. 解决方法:改变数据库编码 第一种方法:改变database 编码: alter data ...

  5. E20170928-hm

    deploy   vt. (尤指军事行动) 使展开; 施展; 有效地利用;部署 bate   vt. 减轻; 压制; 减去; 使软化;             vi. <方> 减少; 减弱 ...

  6. E20170916-hm

    sassy   adj. 无礼的; 漂亮的; <非正,美> <贬>粗鲁的; <褒>时髦的; digest vt. 消化; 整理; compressor  n. 压气 ...

  7. Akka源码分析-Actor创建

    上一篇博客我们介绍了ActorSystem的创建过程,下面我们就研究一下actor的创建过程. val system = ActorSystem("firstActorSystem" ...

  8. warning: remote HEAD refers to nonexistent ref, unable to checkout

    今天使用git clone时候 提示 warning: remote HEAD refers to nonexistent ref, unable to checkout 经过测试解决办法如下 git ...

  9. .Net application,Session,Cache简单比较

    Application 对象用于存储和访问来自任何页面的变量,类似于 session 对象.不同之处在于,所有的用户分享一个 Application 对象,而 session 对象和用户的关系是一一对 ...

  10. 组合的json文件分隔或者拆分

    一个txt文件,内部的json格式如下: { "名称": "#pagecontainer > div.main > div.app-msg > div. ...