codeforces 721E
来源:互联网 发布:天津关键词优化 编辑:程序博客网 时间:2024/05/29 16:05
题目大意
在一条数轴上,你要从0走到
其中有
你要选最多的长度为
并且假如你现在取的段是
问最多取多少段?
解题思路
设
设
假如
容易看出,因为区间不相交,所以
参考程序
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define fo(i,a,b) for(int i=a;i<=b;i++)#define fd(i,a,b) for(int i=a;i>=b;i--)#define maxn 100005#define min(a,b) (((a) < (b)) ? a : b)#define max(a,b) (((a) > (b)) ? a : b)using namespace std;int f[maxn],g[maxn];int l,n,p,t;int head,tail;int ans;int main(){ scanf("%d%d%d%d",&l,&n,&p,&t); head=1; tail=1; f[tail]=0; g[tail]=-t; fo(i,1,n) { int x,y,ans1,ans2; scanf("%d%d",&x,&y); ans1=ans2=0; if (head>1) head--; while (head<=tail && g[head]+t<=y) { int nx=max(x,g[head]+t),ny=y; if (f[head]+(ny-nx)/p>ans1) { ans1=f[head]+(ny-nx)/p; ans2=nx+(ny-nx)/p*p; } else if (f[head]+(ny-nx)/p==ans1) { ans2=min(ans2,nx+(ny-nx)/p*p); } ++head; } if (ans1>ans) { ans=ans1; tail++; f[tail]=ans1; g[tail]=ans2; } } printf("%d",ans); return 0;}
1 0
- codeforces 721E
- codeforces 721E. Road to Home
- codeforces 163E e-Government
- 【Codeforces 163E】E-Government
- Codeforces 78E Evacuation
- 【dp】codeforces 83E
- Codeforces 124 E
- Codeforces 231E
- Codeforces 231E - Cactus
- Codeforces #163 Div2 E
- codeForces 35E
- Codeforces 35E
- Playlist codeforces 268E
- Codeforces 148E(Porcelain)
- codeforces round#177 E
- codeforces 203E Transportation
- CodeForces 254 E Dormitory
- codeforces日记371e
- docker容器内网络请求缓慢问题解决
- 为什么局部内部类只能访问方法中final类型的局部变量?
- 众数问题
- VI编辑器
- Nmap
- codeforces 721E
- 多线程通信
- HashMap与TreeMap区别
- jfinal初步认识
- spring拾遗(一)——@Value注入static属性
- 《深入理解JAVA虚拟机》笔记3——java内存区域
- poj1094 Sorting It All Out 拓扑排序
- IE11的F12功能无法正常使用
- 《圣经 新约》故事:耶稣,保罗,约翰