UVALIVE 5000 Underwater Snipers(二分+贪心)

二分答案

贪心判断


//      whn6325689
//		Mr.Phoebe
//		http://blog.csdn.net/u013007900
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
#include <functional>
#include <numeric>
#pragma comment(linker, "/STACK:1024000000,1024000000")


using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef complex<ld> point;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef vector<int> vi;

#define CLR(x,y) memset(x,y,sizeof(x))
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define lowbit(x) (x&(-x))
#define MID(x,y) (x+((y-x)>>1))
#define eps 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LLINF 1LL<<62

template<class T>
inline bool read(T &n)
{
    T x = 0, tmp = 1; char c = getchar();
    while((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
    if(c == EOF) return false;
    if(c == '-') c = getchar(), tmp = -1;
    while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar();
    n = x*tmp;
    return true;
}
template <class T>
inline void write(T n)
{
    if(n < 0)
    {
        putchar('-');
        n = -n;
    }
    int len = 0,data[20];
    while(n)
    {
        data[len++] = n%10;
        n /= 10;
    }
    if(!len) data[len++] = 0;
    while(len--) putchar(data[len]+48);
}
//-----------------------------------

const int MAXN=10010;

int n,s;
ll k,d;

struct Point
{
	ll x,y;
	bool operator < (const Point& b) const
	{
		return y<b.y;
	}
}a[MAXN],b[MAXN];

bool check(ll y)
{
	for(int i=1;i<=n;i++)
	{
		ll temp=sqrt(d*d-(a[i].y-y)*(a[i].y-y));
		if(temp<0)	return false;
		b[i].x=a[i].x-temp;
		b[i].y=a[i].x+temp;
	}
	sort(b+1,b+n+1);
	int num=0,i=1;
	while(i<=n)
	{
		ll now=b[i].y;
		num++;
		while(i<=n && now>=b[i].x)	i++;
	}
	if(num>s)	return false;
	return true;
}

ll solve(ll l,ll r)
{
	ll ans=-1;
	while(l<=r)
	{
		ll mid=MID(l,r);
		if(check(k-mid))
		{
			l=mid+1;
			ans=mid;
		}
		else
			r=mid-1;
	}
	return ans;
}

int main()
{
//	freopen("data.txt","r",stdin);
	int T,cas=1;
	read(T);
	while(T--)
	{
		read(k),read(n),read(s),read(d);
		for(int i=1;i<=n;i++)
			read(a[i].x),read(a[i].y);
		ll ans=solve(0,d);
		printf("Case %d: ",cas++);
		if(ans==-1)
			puts("IMPOSSIBLE");
		else
			write(ans),putchar('\n');
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值