Codeforces 158E Phone Talks

逃离我推掉我的手 2021-12-23 12:43 260阅读 0赞

http://codeforces.com/contest/158/problem/E

题目大意:

麦克是个名人每天都要接n电话,每通电话给出打来的时间和持续时间,麦克可以选择接或不接,但是只能不接k通电话。如果某通电话打来时麦克正在打电话他可以选择让电话排队,或者忽略不接。当麦克空闲时首先从排队的第一个打来的电话开始接起。麦克是个很懒的人,所以需要大量的睡觉,但是睡觉的时间必须是连续的,因此要求出麦克能睡觉的最大连续时间。

思路:dp[i][j]代表前i个电话,不听j个的最少时间,然后枚举即可

  1. 1 #include<cstdio>
  2. 2 #include<cmath>
  3. 3 #include<algorithm>
  4. 4 #include<cstring>
  5. 5 #include<iostream>
  6. 6 struct node{
  7. 7 int t,d;
  8. 8 }p[200005];
  9. 9 int n,m,f[5005][5005];
  10. 10 bool cmp(node a,node b){
  11. 11 return a.t<b.t;
  12. 12 }
  13. 13 int read(){
  14. 14 int t=0,f=1;char ch=getchar();
  15. 15 while (ch<'0'||ch>'9'){
  16. if (ch=='-') f=-1;ch=getchar();}
  17. 16 while ('0'<=ch&&ch<='9'){t=t*10+ch-'0';ch=getchar();}
  18. 17 return t*f;
  19. 18 }
  20. 19 int main(){
  21. 20 n=read();m=read();
  22. 21 for (int i=0;i<n;i++) p[i].t=read(),p[i].d=read();
  23. 22 std::sort(p,p+n,cmp);
  24. 23 p[n].t=86401;
  25. 24 f[0][1]=0;
  26. 25 f[0][0]=p[0].t+p[0].d-1;
  27. 26 if (m==n){
  28. 27 printf("86400");
  29. 28 return 0;
  30. 29 }
  31. 30 for (int i=1;i<n;i++){
  32. 31 f[i][0]=std::max(p[i].t-1,f[i-1][0])+p[i].d;
  33. 32 for (int j=1;j<=m&&j<=i;j++){
  34. 33 int xx=p[i].t-1;
  35. 34 if (i-1>=j) xx=std::max(xx,f[i-1][j]);
  36. 35 f[i][j]=std::min(f[i-1][j-1],xx+p[i].d);
  37. 36 }
  38. 37 }
  39. 38 int ans=0;
  40. 39 for (int i=0;i<n;i++)
  41. 40 for (int j=0;j<=m;j++){
  42. 41 int x=std::min(n,m-j+i+1);
  43. 42 ans=std::max(ans,p[x].t-1-f[i][j]);
  44. 43 }
  45. 44 printf("%d\n",ans);
  46. 45 return 0;
  47. 46 }

转载于:https://www.cnblogs.com/qzqzgfy/p/5625151.html

发表评论

表情:
评论列表 (有 0 条评论,260人围观)

还没有评论,来说两句吧...

相关阅读

    相关 CodeForces1154E

    [CodeForces1154E][] 题意就是有两个教练,每个教练轮流操作,每次操作会选取所有未被选取的学生中能力值最高的那一个并把这个学生向左向右各\\(k\\)个学生

    相关 codeforces 158B Taxi(贪心)

    [题目链接][Link 1] 题目大意:有n组小学生想要搭乘出租车,每辆出租车最多能坐4个小学生,每组小学生必须坐同一辆出租车,问至少需要多少辆出租车? 分析:要想出租车的

    相关 Codeforces 353E 贪心

    题意:给你一张有向图,第i条边连接i号点和(i + 1) % n号点,问最多可以选择多少个点,使得这些点互相不可达。 思路:容易发现,如果某个边的集合点的数目大于等于2,那么