He
"Problem description"
A length of?? The paper tape, we can be numbered from left to right 0??? (The left end of the tape is labeled as 0). Now there are?? , each time the tape is folded along a certain location, ask what the length of the tape is after all the operations.
"Input Format"
First row two digits??,?? As described in test instructions. Next line?? An integer representing the position of each collapse.
"Output Format"
An integer on one line represents the answer.
"Sample Input"
5 2 3 5
"Sample Output"
2
"Sample Interpretation"
There is a bird in the tree.
"Data size and conventions"
For 60% of data,??,?? ≤3000. For 100% of the data,?? ≤1018,?? ≤3000.
1#include <iostream>2#include <cstdio>3 #defineULL unsigned long Long4 using namespacestd;5ULL f[3005],n,l,r;6 intm;7 inline ULL read ()8 {9ULL w=0, flag=1;CharCh=GetChar ();Ten while(ch>'9'|| ch<'0'){if(ch=='-') flag=-1; ch=GetChar ();} One while(ch<='9'&&ch>='0') {w=w*Ten+ch-'0'; ch=GetChar ();} A returnw*Flag; - } - intMain () the { -Freopen ("he.in","R", stdin); -Freopen ("He.out","W", stdout); -N=read (); m=read (); +L=0; R=N; - for(intI=1; i<=m;i++) f[i]=read (); + for(intI=1; i<=m;i++) A { at - if(f[i]*2>=L+R) R=f[i];//drop the right . - ElseL=f[i];//drop the left . - - for(intj=i+1; j<=m;j++) - { in if(F[j]>r) f[j]=r*2-F[j]; - if(f[j]<l) f[j]=l*2-F[j]; to } + - } the *cout<<r-l<<Endl; $ fclose (stdin);Panax Notoginseng fclose (stdout); - return 0; the}
2016.10.30 Jinan study Day2 pm T1