bzoj4509 "Usaco2016 Jan" Angry cows

Source: Internet
Author: User

4509: [Usaco2016 jan]angry cows time limit: Sec Memory Limit: ten MB
Submit: Solved: 38
[Submit] [Status] [Discuss] Descriptionbessie The cow have designed what she thinks'll be is the next big hit video game: "Angry cows". The premise, which she believes is completely original, was that the player shoots a cow with a slingshot into a one-dimens Ional scene consisting of a set of hay bales located at various points on a number line; The cow lands with sufficient force to detonate the hay bales in close proximity to her landing site, which in turn might Set of a chain reaction that causes additional hay bales to explode. The goal is to use a, cow to start a chain reaction that detonates all the hay bales. There is NN hay bales located at distinct integer positions x1,x2,..., xnx1,x2,..., XN on the number line. If A cow is launched with power RR landing at position xx, this would causes a blast of "radius RR", engulfing all hay bale s within the range x? R...x+rx? R...x+r. These hay bales then themselves explode (all simultaneously), each with a blast radius of r?1r?1. Any not-yet-exploded bales caught in these BLasts then all explode (all simultaneously) with the blast radius r?2r?2, and so on. Please determine the minimum amount of power RR with which a single cow could be launched so, if it lands at an APPROPR Iate location, it'll cause subsequent detonation of every single hay bale in the scene.

Inputthe first line of input contains NN (2≤n≤50,000). The remaining NN lines all contain integers x1...xn (the range 0 ... 1,000,000,000).

Outputplease output the minimum power RR with which a cow must is launched in order to detonate all the hay bales. Answers should is rounded and printed to exactly 1 decimal point.

Sample Input5
8
10
3
11
1Sample Output3.0
In this example, a cow launched with power 3 at, say, location 5, would cause immediate detonation of hay bales at position s 3 and 8. These then explode (simultaneously) each with blast radius 2, engulfing bales at positions 1 and ten, which next explode (s imultaneously) with blast radius 1, engulfing the final bale at position one, which finally explodes with blast radius 0. HINT

Source

Gold




DP = =

F[i] means to blow up all the explosives before I, the minimum required radius at I point.

G[i] means to blow up all the explosives after I, the minimum required radius at I point.

Find J<i and a[i]-a[j]>f[j]+1 the last J,f[i]=min (a[i]-a[j],f[j+1]+1), the G array similarly.

Finally enumerate the starting attack interval and compute the answer.

One trick is that the fractional part of the answer can only be 0 or 0.5, so multiplying all the numbers by 2 avoids the decimal problem, and the final answer is divided by 2.




#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring > #include <algorithm> #define F (I,j,n) for (int. i=j;i<=n;i++) #define D (i,j,n) for (int i=j;i>=n;i--) # Define ll long Long#define N 50005#define inf 2000000000using namespace std;int n,a[n],f[n],g[n];inline int read () {int x=0 , F=1;char Ch=getchar (); while (ch< ' 0 ' | | Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();} while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;} int main () {n=read (); F (I,1,n) A[i]=read () *2;sort (a+1,a+n+1); F (i,1,n) F[i]=g[i]=inf;int t=1;f[1]=0; F (I,2,n) {while (t+1<i&&a[i]-a[t+1]>f[t+1]+2) t++;f[i]=min (a[i]-a[t],f[t+1]+2);} T=n;g[n]=0;d (i,n-1,1) {while (t-1>i&&a[t-1]-a[i]>g[t-1]+2) t--;g[i]=min (a[t]-a[i],g[t-1]+2);} int ans=inf;for (int i=1,j=n;i<j;) {ans=min (Ans,max ((a[j]-a[i))/2,max (F[i],g[j]) +2), if (f[i+1]<g[j-1]) i++; else j--;} printf ("%.1lf\n", (double) ans/2); return 0;}


bzoj4509 "Usaco2016 Jan" Angry cows

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.