折纸
题解
考试时无限接近正解,然而最终也只是接近而已了
考虑模拟会爆炸,拿手折纸条试一试,很简单
考你动手能力
代码
#include<bits/stdc++.h> using namespace std; #define ll long long #define A 3100000 ll cj[A],questions[A]; ll len,l,r,n,QAQ; int main(){ scanf("%lld%lld",&len,&QAQ); l=0,r=len; for(ll i=1,a;i<=QAQ;i++){ scanf("%lld",&questions[i]); } for(ll i=1;i<=QAQ;i++){ ll llen=questions[i]-l; ll rlen=r-questions[i]; // printf("ques=%lld llen=%lld rlen=%lld ",questions[i],l,r); if(llen==0||rlen==0) continue; if(llen<rlen){ l=questions[i]; for(ll j=i+1;j<=QAQ;j++){ if(questions[j]<questions[i]) questions[j]=questions[i]+abs(questions[j]-questions[i]); } } if(llen>=rlen){ r=questions[i]; for(ll j=i+1;j<=QAQ;j++){ if(questions[j]>questions[i]) questions[j]=questions[i]-abs(questions[j]-questions[i]); } } } printf("%lld ",r-l); }