P6842 Strip 题解
题意简述
对一个长度为
注意到 long long 类型进行运算。
以一个例子引入。
我们假设
- 对
3 所在的位置进行折叠,得到\{3,(2;4),(1;5),0\} 。 - 对
4 所在的位置折叠,得到\{(2;4),(1;3;5),0\} 。 - 对
1 所在的位置折叠,得到\{(1;3;5),(0;2;4)\} 。 - 此时纸条上有
2 个端点,得到答案ans=1 。
基本思路
使用
使用
因为每次向左折与向右折本质上是一样的,而且每次向右折可以保证
为什么更新方式是
更新
最后输出
示例代码
#include<iostream>
#define LG086 main
using namespace std;
using ll = long long;
const int N = 1e4+5;
ll n,k,last[N];
int LG086(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n>>k;
ll l=0,r=n,ans=n;
for(ll _(1),a;_<=k;_++){
cin>>a;
for(int i(1);i<_;i++)
a=max(a,2*last[i]-a);
last[_]=a;r=max(r,a*2-l);
ans=r-a;l=a;
}
cout<<ans;
return 0;
}