「CF508C」Anya and Ghosts
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.
For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi‘s are distinct. Each visit lasts exactly one second.
What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight.That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle’s burning and the minimum number of candles that should burn during each visit.
The next line contains m space-separated numbers wi (1 ≤ i ≤ m, 1 ≤ wi ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi‘s are distinct, they follow in the strictly increasing order.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that.
If that is impossible, print - 1.
1 2 |
1 8 3 10 |
1 |
3 |
1 2 |
2 10 1 5 8 |
1 |
1 |
1 2 |
1 1 3 10 |
1 |
-1 |
Anya can start lighting a candle in the same second with ghost visit. But this candle isn’t counted as burning at this visit.
It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.
In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.
In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.
In the third sample test the answer is - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
题解
考虑前i次访问时,显然将蜡烛尽量迟点亮是较优的
对于wi时间的访问,要求在wi-t到wi-1时间内开始点亮r根蜡烛
统计这个区间内蜡烛数,如果<r,则从wi-1往前选择一些时间点点蜡烛
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<set> #include<ctime> #include<vector> #include<queue> #include<algorithm> #include<map> #include<cmath> #define eps 1e-8 #define inf 1000000000 #define pa pair<int,int> #define ll long long using namespace std; int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int m,t,r,ans; int w[305]; map<int,bool> mark; int main() { m=read();t=read();r=read(); for(int i=1;i<=m;i++) w[i]=read(); for(int i=1;i<=m;i++) { int cnt=0; for(int j=w[i]-1;j>=w[i]-t;j--) if(mark[j])cnt++; for(int j=w[i]-1;j>=w[i]-t&&r-cnt>0;j--) if(!mark[j])mark[j]=1,ans++,cnt++; if(r-cnt>0){puts("-1");return 0;} } printf("%d\n",ans); return 0; } |
分类目录
热门文章
- 12125NOIP1999拦截导弹
- 11666「BZOJ3261」最大异或和
- 11417NOIP2010导弹拦截
- 100072017 训练赛 1 by hzwer
- 9610「百度之星2017」程序设计大赛 初赛(B)
- 8521「JoyOI1048」田忌赛马
- 8485NOIP2010引水入城
- 83592017ACM萧山训练第4场(CTUO 2015)
- 83512017ACM萧山训练第3场(World Final 2013)
- 8192「CF718X」Codeforces Round #373 (Div. 1)
- 7843「BZOJ3709」[PA2014] Bohater
- 7821NOI2010 超级钢琴
- 7776「BZOJ1150」[CTSC2007] 数据备份Backup
- 7754「BZOJ1046」[HAOI2007] 上升序列
- 7684「BZOJ2811」[Apio2012] Guard
- 7596「BZOJ2288」「POJ Challenge」生日礼物
- 7414「BZOJ3166」[HEOI2013] Alo
- 7323「BZOJ2151」种树
- 7243「BZOJ3105」[CQOI2013] 新Nim游戏
- 7096「BZOJ4027」[HEOI2015] 兔子与樱花
- 6946「CF1280X」Codeforces Round #607 (Div. 1)
- 6928NOIP2012国王游戏
- 6873「BZOJ1086」[SCOI2005] 王室联邦
- 6839NOI2014随机数生成器
- 6828NOIP2007纪念品分组
- 6719「CF538X」Codeforces Round #300
- 6655「BZOJ1043」[HAOI2008] 下落的圆盘
- 6653POJ训练记录2
- 66032017ACM萧山训练第5场(2016 Pacific Northwest - Division 1)
- 63302015 ACM / ICPC EC - Final
- 6294「codechef」January Challenge 2015
- 6161NOIP2004合并果子
- 6142「BZOJ1229」[USACO2008 Nov] toy 玩具
- 6136NOI2009诗人小G
近期评论
- 匿名发表在《留言板》
- 匿名发表在《hzwer.com 博客导航》
- 匿名发表在《hzwer.com 博客导航》
- 匿名发表在《hzwer.com 博客导航》
- 匿名发表在《留言板》