bzoj4509【Usaco2016 Jan】Angry Cows

4509: [Usaco2016 Jan]Angry Cows

Time Limit: 10 Sec  Memory Limit: 128 MB

Submit: 83  Solved: 38

[Submit][Status][Discuss]

Description

Bessie the cow has designed what she thinks will be the next big hit video game: "Angry Cows". The premise, which she believes is completely original, is that the player shoots a cow with a slingshot
into a one-dimensional 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 single cow to start a chain reaction that detonates all the hay bales.

There are 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 will causes a blast of "radius
RR", engulfing all hay bales 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 blast
radius R?2R?2, and so on.

Please determine the minimum amount of power RR with which a single cow may be launched so that, if it lands at an appropriate location, it will cause subsequent detonation of every single hay bale
in the scene.

Input

The first line of input contains NN (2≤N≤50,000). The remaining NN lines all contain integers x1…xN (each in the range 0…1,000,000,000).

Output

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

Sample Input

5

8

10

3

11

1

Sample Output

3.0

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

HINT

Source

Gold

DP= =

f[i]表示要炸掉i之前的所有炸药包,在i点最少需要的半径。

g[i]表示要炸掉i之后的所有炸药包,在i点最少需要的半径。

找到j<i且a[i]-a[j]>f[j]+1的最后一个j,f[i]=min(a[i]-a[j],f[j+1]+1),g数组同理。

最后枚举起始的攻击区间,计算答案。

有一个小技巧,答案的小数部分只可能是0或者0.5,所以将所有数乘以2就可以避免小数问题,最后答案再除以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 2000000000
using 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;
}
时间: 2024-10-22 16:12:56

bzoj4509【Usaco2016 Jan】Angry Cows的相关文章

【POJ 3621】Sightseeing Cows

Sightseeing Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7984   Accepted: 2685 Description Farmer John has decided to reward his cows for their hard work by taking them on a tour of the big city! The cows must decide how best to

【二分查找】POJ2456-Aggressive cows

[题目大意] 有N间牛舍和M头牛,告诉你每个牛舍的位置,求出两头牛之间最小距离的最大值. [思路] 二分判断两头牛之间的最小距离d,通过贪心法进行验证. 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 using namespace std; 7 const int MAXN=100000+5

bzoj4576【Usaco2016 Open】262144

4576: [Usaco2016 Open]262144 Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 97  Solved: 73 [Submit][Status][Discuss] Description Bessie likes downloading games to play on her cell phone, even though she does find the small touch screen rather cumbe

【POJ - 2456】Aggressive cows(二分)

Aggressive cows 直接上中文了 Descriptions 农夫 John 建造了一座很长的畜栏,它包括N (2 <= N <= 100,000)个隔间,这些小隔间依次编号为x1,...,xN (0 <= xi <= 1,000,000,000). 但是,John的X (2 <= X <= N)头牛们并不喜欢这种布局,而且几头牛放在一个隔间里,他们就要发生争斗.为了不让牛互相伤害.John决定自己给牛分配隔间,使任意两头牛之间的最小距离尽可能的大,那么,这个

【BZOJ3888】【Usaco2015 Jan】Stampede 线段树判区间覆盖

广告: #include <stdio.h> int main() { puts("转载请注明出处[vmurder]谢谢"); puts("网址:blog.csdn.net/vmurder/article/details/44066313"); } 题意: PoPoQQQ站在原点上向y轴正半轴看,然后有一群羊驼从他眼前飞过.这些羊驼初始都在第二象限,尾巴在(Xi,Yi),头在(Xi+1,Yi),每Ci秒向右走一个单位. PoPoQQQ能看见一匹羊驼当且仅

【BZOJ3889】【Usaco2015 Jan】Cow Routing 双键值最短路

广告: #include <stdio.h> int main() { puts("转载请注明出处[vmurder]谢谢"); puts("网址:blog.csdn.net/vmurder/article/details/44064091"); } 题意: 从样例讲起. 第一行 s,t,m表示:起点,终点,m条航线. 然后m组,每组第一行len,n表示这条航线的代价, 这类似于公交车,只要用了就花这些钱,但是用多少都这些钱. 注意是单向边. 举例: 23

【BZOJ 3048】【USACO2013 Jan】Cow Lineup 滑块思想

昨天下午想了好久没想出来,果然是很弱,思考能力低下. 用的类似单调队列的思想,维护一个长度为$k+1$的滑块,每次统计下$ans$就可以了 #include<cstdio> #include<algorithm> using namespace std; int n, k, H[100003], id[100003], a[100003], cnt = 0, c[100003], st, ans = 0; inline bool cmp(int X, int Y) { return

【BZOJ3885】【Usaco2015 Jan】Cow Rectangles 某奇怪的最大子矩形

广告: #include <stdio.h> int main() { puts("转载请注明出处[vmurder]谢谢"); puts("网址:blog.csdn.net/vmurder/article/details/44095063"); } 题意: 坐标系上给出n个点,分"H"和"G",一个整点坐标上至多一个点. 现在求一个不包含"G"的包含尽量多"H"的子矩形,然后

【BZOJ3886】【Usaco2015 Jan】Moovie Mooving 状态压缩 动态规划

广告: #include <stdio.h> int main() { puts("转载请注明出处[vmurder]谢谢"); puts("网址:blog.csdn.net/vmurder/article/details/44040735"); } 题意: PoPoQQQ要在电影院里呆L分钟,这段时间他要看小型电影度过.电影一共N部,每部都播放于若干段可能重叠的区间,PoPoQQQ决不会看同一部电影两次.现在问他要看最少几部电影才能度过这段时间? 注:必