Codeforces 158E Phone Talks
http://codeforces.com/contest/158/problem/E
题目大意:
麦克是个名人每天都要接n电话,每通电话给出打来的时间和持续时间,麦克可以选择接或不接,但是只能不接k通电话。如果某通电话打来时麦克正在打电话他可以选择让电话排队,或者忽略不接。当麦克空闲时首先从排队的第一个打来的电话开始接起。麦克是个很懒的人,所以需要大量的睡觉,但是睡觉的时间必须是连续的,因此要求出麦克能睡觉的最大连续时间。
思路:dp[i][j]代表前i个电话,不听j个的最少时间,然后枚举即可
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
struct node{
int t,d;
}p[];
int n,m,f[][];
bool cmp(node a,node b){
return a.t<b.t;
}
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
int main(){
n=read();m=read();
for (int i=;i<n;i++) p[i].t=read(),p[i].d=read();
std::sort(p,p+n,cmp);
p[n].t=;
f[][]=;
f[][]=p[].t+p[].d-;
if (m==n){
printf("");
return ;
}
for (int i=;i<n;i++){
f[i][]=std::max(p[i].t-,f[i-][])+p[i].d;
for (int j=;j<=m&&j<=i;j++){
int xx=p[i].t-;
if (i->=j) xx=std::max(xx,f[i-][j]);
f[i][j]=std::min(f[i-][j-],xx+p[i].d);
}
}
int ans=;
for (int i=;i<n;i++)
for (int j=;j<=m;j++){
int x=std::min(n,m-j+i+);
ans=std::max(ans,p[x].t--f[i][j]);
}
printf("%d\n",ans);
return ;
}
Codeforces 158E Phone Talks的更多相关文章
- Codeforces 158E Phone Talks:dp
题目链接:http://codeforces.com/problemset/problem/158/E 题意: 你有n个电话要接,每个电话打进来的时刻为第t[i]分钟,时长为d[i]分钟. 每一个电话 ...
- codeforces E. Phone Talks(dp)
题目链接:http://codeforces.com/contest/158/problem/E 题意:给出一些电话,有打进来的时间和持续的时间,如果人在打电话,那么新打进来的电话入队,如果人没有打电 ...
- Codeforces Round #561 (Div. 2) C. A Tale of Two Lands
链接:https://codeforces.com/contest/1166/problem/C 题意: The legend of the foundation of Vectorland talk ...
- VK Cup 2012 Qualification Round 1 E. Phone Talks —— DP
题目链接:http://codeforces.com/contest/158/problem/E E. Phone Talks time limit per test 3 seconds memory ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
随机推荐
- [LeetCode] 134. Gas Station 解题思路
There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...
- Laravel5.2 下使用Form
laravel到了5.1.*以上版本,便没有了illuminate/html类库的支持, 我试着把illuminate/html类库加入了laravel5.2,依然没有用, 但是laravelcoll ...
- [深入React] 5.MVC
react 是一种典型的MVC框架. 在jquery中,我们都是针对dom编程,由dom事件触发dom改变,MVC三层代码混在一起. 比如点击变颜色 $('#btn').click(function( ...
- [原创作品]Javascript内存管理机制
如果你也喜欢分享,欢迎加入我们:QQ group:164858883 内存策略:堆内存和栈内存栈内存:在函数中定义的一些基本类型的变量和对象的引用变量都是在函数的栈内存中分配.当在一段代码块中定义一个 ...
- 深入解读ESB与SOA的关系
时至今日,SOA的概念渐渐清晰了. 有关ESB的概念,已经吵了好多年了,还是没有定论. 我个人认为,ESB本来就是抽象的概念,而且内涵丰富,在不同的场合含义不同.因此应该从不同的角度来认识. ...
- P2P/WSN信任建模与仿真平台
1.ART Testbed 该平台是基于多代理的信任仿真平台,官网的介绍如下: The Agent Reputation and Trust (ART) Testbed initiative has ...
- 文件下载,带转码->pdf->swf
private String upload = "保存的路径"; //文件下载 public String download() { //初始化 this.initContext( ...
- Selenium2(webdriver)入门之TestNG的使用
一.在Eclipse中安装TestNG 1.打开eclipse-->help-->Install New Software-->Add,输入Name和Location后,点击OK. ...
- 一、Solr综述
什么是Solr搜索 我们经常会用到搜索功能,所以也比较熟悉,这里就简单的介绍一下搜索的原理. 当然只是介绍solr的原理,并不是搜索引擎的原理,那会更复杂. 流程图 这是一个非常简单的流程图: Use ...
- Transparency Tutorial with C# - Part 1
Download demo project - 4 Kb Download source - 6 Kb Download demo project - 5 Kb Download source - 6 ...