纸带折叠

源代码:

#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
LL m,n,i[3001];
int main() //万恶的模拟主义势力。
{
    scanf("%lld%lld",&n,&m);
    for (LL a=1;a<=m;a++)
      scanf("%lld",&i[a]);
    LL Left=0,Right=n;
    for (LL a=1;a<=m;a++)
    {
        for (LL b=a+1;b<=m;b++)
          if (i[b]>=Left&&i[b]<=i[a])
            i[b]=(i[a]<<1)-i[b];
        Right=max((i[a]<<1)-Left,Right);
        Left=i[a]; //统一右折。
        for (LL b=a+1;b<=m;b++)
          i[b]-=Left;
        Right-=Left;
        Left-=Left; //转变为一个全新的纸带。
    }
    printf("%lld",Right-Left);
    return 0;
} //自己实在是太low了。
原文地址:https://www.cnblogs.com/Ackermann/p/6013271.html