Uvalive 3177 Great Wall Guard

Source: Internet
Author: User

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&itemid=8&page=show_problem& problem=1178

Http://7xjob4.com1.z0.glb.clouddn.com/8e1ee1ef5ea10e46ebda75b88b058f47

Test instructions: N personal circle, each person has a different or equal number of gifts, adjacent gifts can not be the same, the minimum total number of gifts.

Idea: N is even: the maximum number of gifts for two adjacent people; n is an odd number: two-way choice of gift quantity, see if it is feasible, set the first person gift for the former, the number of even-numbered people try to take in front, odd people try to take in the back, and finally check whether the last person's gift and the first person

1#include <bits/stdc++.h>2 using namespacestd;3 4 intN;5 intr[100005],left[100005],right[100005];6 7 intCheckintp)8 {9     inti,j;Ten     intx=r[1],y=p-r[1]; Oneleft[1]=x,right[1]=0; A      for(i=2; i<=n;i++) -     { -         if(i%2==0) the         { -Left[i]=min (x-left[i-1],r[i]); -right[i]=r[i]-Left[i]; -         } +         Else -         { +Right[i]=min (y-right[i-1],r[i]); Aleft[i]=r[i]-Right[i]; at         } -     } -     if(left[n]==0) -         return 1; -     return 0; - } in  - intMain () to { +     inti,j; -      while(SCANF ("%d", &n)!=eof && n!=0) the     { *          for(i=1; i<=n;i++) $         {Panax Notoginsengscanf"%d",&r[i]); -         } the         if(n==1) +         { Aprintf"%d\n", r[1]); the             Continue; +         } -  $         intL=0, r=0; r[n+1]=r[1]; $          for(i=1; i<=n;i++) L=max (l,r[i]+r[i+1]); -         if(n%2==1) -         { the              for(i=1; i<=n;i++) R=max (r,r[i]*3); -              while(l<R)Wuyi             { the                 intMid= (L+R)/2; -                 if(check (mid)) Wu                 { -R=mid; About                 } $                 Else -                 { -L=mid+1; -                 } A             } +         } theprintf"%d\n", L); -     } $     return 0; the}
View Code

Uvalive 3177 Great Wall Guard

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.