BZOJ3827: [Poi2014]Around the world
来源:互联网 发布:怎么登录熊片数据库 编辑:程序博客网 时间:2024/05/19 20:37
将一段延伸到尽可能接近d,设其长为L,发现n个开头的走法在这一段内都会占据L个位置中的一个,根据这个性质就可以dp了
把环拉成链,倍长,对n+1~2n做dp,st[i]表示走到i,起点是哪个点,f[i]表示st[i]走到i需要的最少步数,f[i]=min f[j]+1 (s[i]-s[j]<=d)
code:
#include<set>#include<map>#include<deque>#include<queue>#include<stack>#include<cmath>#include<ctime>#include<bitset>#include<string>#include<vector>#include<cstdio>#include<cstdlib>#include<cstring>#include<climits>#define ll long longusing namespace std;inline void read(int &x){ char c; while(!((c=getchar())>='0'&&c<='9')); x=c-'0'; while((c=getchar())>='0'&&c<='9') (x*=10)+=c-'0';}const int maxn = 2000005;int n,m,u;int s[maxn];int f[maxn],st[maxn];int main(){ read(n); read(m); for(int i=1;i<=n;i++) { int x; read(x); if(u<x)u=x; s[i]=s[i-1]+x; } for(int i=n+1;i<=n+n;i++) s[i]=s[i-1]+s[i-n]-s[i-n-1]; for(int i=1;i<=n;i++) st[i]=i,f[i]=0; while(m--) { int d; read(d); if(d<u) { puts("NIE");continue; } int j=1; for(int i=n+1;;i++) { while(s[i]-s[j]>d)j++; f[i]=f[j]+1; st[i]=st[j]; if(i-st[i]>=n) { printf("%d\n",f[i]);break; } } } return 0;}
阅读全文
0 0
- bzoj3827:[Poi2014]Around the world
- BZOJ3827[Poi2014] Around the world
- BZOJ3827: [Poi2014]Around the world
- 【BZOJ3827】[Poi2014]Around the world【尺取法】【并查集】
- poj 2432 Around the world bfs+哈希
- bnuoj 52305 Around the World dfs+排列组合
- 2016 四川省赛 Around the World
- CHILDBIRTH TRADITIONS AROUND THE WORLD: CHINA
- Ganymede Around the world中我的名字
- Around the World in Eighty Days 5/201
- Around the World in Eighty Days 19/201
- BNU-52305-Around the World(四川省赛H题)
- bzoj1748 [Usaco2005 open]Around the world 环球飞行
- ICPCCamp 2016 Day1 ftiasch's Contest #4(Around the world-树,构造)
- Around the World in 60 Days: Getting Deep Speech to Work in Mandarin
- 2016年四川省赛H题 Around the World(BEST定理||树形dp)
- dTrekking around the Hol
- j2ee ## will turn this world around
- 74. Search a 2D Matrix
- 简单的SpringBoot工程搭建
- python中defaultdict方法的使用
- HTML标签marquee实现滚动效果
- UDP 实例
- BZOJ3827: [Poi2014]Around the world
- MapReduce 读取ORC格式文件
- xss安全漏洞分析以及项目实施解决方案
- 7.5
- Java类加载机制与Tomcat类加载器架构
- NoSQLUnit Core
- 指针,数组指针,指针数组的剖析
- jvm四:jvm内存说明
- 1035. 插入与归并(25)---Python