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的概 ...
随机推荐
- jsonp实现跨域资源访问
平时项目中处理ajax跨域资源请求时,例如www.example2.com上的某个页面要请求www.example1.com的数据,我们使用得较多的是jsonp方式.jsonp通过JavaScript ...
- HDOJ 1303 Doubles(简单题)
Problem Description As part of an arithmetic competency program, your students will be given randoml ...
- MD中bitmap源代码分析--入题概述
在MD模块中,各级raid都使用的一份bitmap的源码,也就是说共用一种bitmap的流程,下面以raid1的使用为例来分析bitmap的工作原理. 在使用raid1磁盘阵列的时候,对于数据的可靠性 ...
- java随机数生成器
一.java.lang.Math.Random 调用这个Math.Random()函数能够返回带正号的double值,取值范围是[0.0,1.0)的左闭右开区间,并在该范围内(近似)均匀分布. 二.j ...
- css样式-表格优化
1.表格的初步优化 index.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8&qu ...
- css3 渐变linear-gradient
background: -moz-linear-gradient(top, #FC641C, #FC761C); 参数:其共有三个参数,第一个参数表示线性渐变的方向,top 是从上到下.left 是从 ...
- (转)关于Android的nodpi,xhdpi,hdpi,mdpi,ldpi
首先是几个基本概念:1.屏幕尺寸Screen size即显示屏幕的实际大小,按照屏幕的对角线进行测量.为简单起见,Android把所有的屏幕大小分为四种尺寸:小,普通,大,超大(分别对应:small, ...
- 关于kendo ui的使用改变颜色方式
1.概述: 在网上kendo ui教程中示例在演示的时候引用的css样式为kendo.common.min.css与kendo.default.min.css这两个外部样式,大家有没有发现,这两个样式 ...
- ACtivity实现欢迎界面并添加动画切换效果
先看效果: 中间切换动画没来得及截图,凑合着看吧. 主要是java代码的实现: Welcom.java package kehr.activity.welcome; import android.ap ...
- POJ 2502 Subway(迪杰斯特拉)
Subway Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6692 Accepted: 2177 Descriptio ...