题目链接:http://lightoj.com/volume_showproblem.php?problem=1383
Time Limit: 4 second(s) | Memory Limit: 32 MB |
King Motashota is in a war against the mighty Bachchaloks. He has formed a well trained army of snipers, and planning to use them as much as possible. In one of the missions, he has S snipers. They will be dispatched to get rid of the soldiers guarding the bank of the river Nodi.
From satellite images, Motashota has located positions of all enemy soldiers. Now, the plan is, snipers will take their positions. They are excellent swimmers, so, you can assume that they won't get caught, while taking position. Upon order from Motashota, they will start shooting enemy soldiers. A sniper can shoot a soldier, if Euclidean Distance between the soldier and sniper is no more than D. After the snipers get rid of all the soldiers, they can proceed with the operation. So, it is important for them to position the snipers in such a way that, all soldiers are within the range of at least one sniper.
In addition, when snipers start shooting, the guards will be alert, and thus, snipers can't change their position, they can only continue shooting from their position.
The river bank is defined by the horizontal line y = k. All points (x, y) where y > k is in the enemy territory, and if y < k, then it's on the water. You will be given location of N soldiers, strictly in the enemy territory; you have to place S soldiers in the water, so that they can kill all soldiers. For security reasons, the snipers should be as far from the bank as possible. For any sniper in position (xi, yi), the distance from the bank is |yi - k|. If, for all snipers, the minimum of them is M = min{|yi - k|}, you have to maximize M.
Both the soldiers and snipers are really superstitious. They will stay only in integer coordinates.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with a black line. Next line contains four integers, k (-108 ≤ k ≤ 108), N (1 ≤ N ≤ 10000), S (1 ≤ S ≤ 10000) and D (1 ≤ D ≤ 109), the position of the bank, number of guards and number of snipers, and the range of the snipers.
This is followed by N lines, each containing a pair of integers (xi, yi) the position of ith guard (-108 ≤ xi ≤ 108, k < yi ≤ 108).
Output
For each case, print the case number and M which is described in the statement. If the snipers cannot kill all the guards, print "impossible".
Sample Input | Output for Sample Input |
2
0 3 2 4 1 1 3 2 9 1
0 3 1 4 1 1 3 2 9 1 | Case 1: 2 Case 2: impossible |
Developed and Maintained by
JANE ALAM JAN |
Copyright © 2012
LightOJ, Jane Alam Jan |
题目大意:河y = k,河岸上是敌人,给出敌人的坐标,我军在水里有S个狙击手,射程为D,求能射杀所有敌人离河岸最远的距离,,
题目解析:二分距离,求出所有敌人的最佳射程L和R,然后合理安排狙击手,
代码如下:
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<string>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#define N 10009
using namespace std;
const int inf = 1e9;
const int mod = 1<<30;
const double eps = 1e-8;
const double pi = acos(-1.0);
typedef long long LL;
struct node
{
int x, y;
double L, R;
} t[N], dis[N];
int k, n, s, d;
int cmp(node a, node b)
{
return a.R != b.R ? a.R < b.R : a.L < b.L;
}
int check(int md)
{
int i, k;
for(i = 1; i <= n; i++)
{
if(t[i].y + md > d) return 0;
}
for(i = 1; i <= n; i++)
{
double y = 1.0 * t[i].y + md;
double x = sqrt(1.0 * d * d - y * y);
dis[i].L = t[i].x - x;
dis[i].R = t[i].x + x;
}
sort(dis + 1, dis + 1 + n, cmp);
k = 1;
double now = dis[1].R;
for(i = 2; i <= n; i++)
{
if(now < dis[i].L) k++, now = dis[i].R;
}
return k <= s;
}
int solve()
{
int ans = -1, l, r, md;
l = 0, r = d;
while(l <= r)
{
md = (l + r) >> 1;
if(check(md)) ans = md, l = md + 1;
else r = md - 1;
}
return ans;
}
int main()
{
int T, i, cnt = 0;
scanf("%d", &T);
while(T--)
{
scanf("%d%d%d%d", &k, &n, &s, &d);
for(i = 1; i <= n; i++)
{
scanf("%d%d", &t[i].x, &t[i].y);
t[i].y -= k;
}
int ans = solve();
if(ans == -1) printf("Case %d: impossible\n", ++cnt);
else printf("Case %d: %d\n", ++cnt, ans);
}
return 0;
}