Uva Great Wall guard--1335-beijing guards

Source: Internet
Author: User

Two-point search + some tricks

1#include <iostream>2 using namespacestd;3 4 Const intmaxn=100000+Ten;5 intn,r[maxn],left[maxn],right[maxn];//because no calculation scheme, so you can press "1~r[i" and "r[i]+1~p" each take a few points, then did not think of this with set class write a time-consuming ~ ~ ~ (>_ <) ~ ~ ~6 7 BOOLOkintp)8 {9     intx=r[1],y=p-r[1];Tenleft[1]=x; right[1]=0; One      for(intI=2; i<=n;i++) A     { -         if(i&1) -         { theRight[i]=min (y-right[i-1],r[i]);//Odd guard first take the right. -left[i]=r[i]-right[i];//Look at the left to a few -         } -         Else +         { -Left[i]=min (x-left[i-1],r[i]);//Even the guard first take the left. +right[i]=r[i]-left[i];//look at the right to a few A         } at     } -     returnleft[n]==0;//The Nth guard on the left is 0 o'clock - } -  - intMain () - { in      while(cin>>n&&N) -     { to          for(intI=1; i<=n;i++) +Cin>>R[i]; -         if(n==1) {cout<<r[1]<<endl;Continue;} This place pits me. ther[n+1]=r[1]; *         intL=0, r=0; $          for(intI=1; i<=n;i++) L=max (l,r[i]+r[i+1]);Panax Notoginseng         if(n&1) -         { the              for(intI=1; i<=n;i++) R=max (r,r[i]*3); +              while(l<R) A             { the                 intM= (L+R)/2; +                 if(OK (M)) R=M; -                 Elsel=m+1; $             } $         } -cout<<l<<Endl; -     } the}

Uva Great Wall guard--1335-beijing guards

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.