# Bzoj1563 [noi2009]诗人小g

## 四边形不等式优化入门题

Posted by yjjr's blog on January 18, 2018

# 题目

Output 对于每组数据，若最小的不协调度不超过1018，则第一行一个数表示不协调度若最小的不协调度超过1018，则输出”Too hard to arrange”(不包含引号)。每个输出后面加”——————–” Sample Input 4

4 9 3

brysj,

hhrhl.

yqqlm,

gsycl.

4 9 2

brysj,

hhrhl.

yqqlm,

gsycl.

1 1005 6

poet

1 1004 6

poet

Sample Output 108

32

Too hard to arrange

1000000000000000000

【样例说明】

HINT

# 分析

byvoid的题解好神啊，我也懒得写了https://www.byvoid.com/zhs/blog/noi-2009-poet

# code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long double
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
#define inf 1000000000000000000LL
using namespace std;
{
ll f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int maxn=1e5+6;
int T,n,l,p;
ll s[maxn],f[maxn],from[maxn];
char ch[maxn][36];
struct node{int l,r,p;}que[maxn];
ll pow(ll x){if(x<0)x=-x;ll re=1;rep(i,1,p)re*=x;return re;}
ll cal(int j,int i){return f[j]+pow(s[i]-s[j]+(i-j-1)-l);}
int find(node t,int x){//二分查找最优决策点
int l=t.l,r=t.r,mid;
while(l<=r){
mid=(l+r)>>1;
if(cal(t.p,mid)<cal(x,mid))l=mid+1;else r=mid-1;
}
return l;
}
void dp(){
rep(i,1,n){
else{int t=find(que[tail],i);que[tail].r=t-1;que[++tail]=(node){t,n,i};}
}//单调队列优化
}
}
int main()
{