题目链接:http://lightoj.com/volume_showproblem.php?problem=1383

题意:在平面图中,有一条河,用直线y=k表示,河上面(y>k)的都是敌方区域,y<k的都是水,现在有s个狙击手在水中不知道他们的位置;有n个敌军的士兵,已知他们的坐标;

狙击手有一个射击的范围 D,现在要满足所有敌方士兵都在狙击手的射击范围内,而且还要离河的距离M尽量的远,其中M是所有狙击手离河的距离最近的那个;如果不能满足输出“impossible”

距离最大化,我们可以二分,对于给定的一个距离d,看s个点是否能包含n个点即可;怎么判断就是相当于poj的一道雷达的那题,用贪心即可;

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
using namespace std;
#define met(a, b) memset(a, b, sizeof(a))
#define maxn 10005
#define maxm 20005
#define INF 0x3f3f3f3f
typedef long long LL; struct node
{
int x, y;
double L, R;
}a[maxn], b[maxn]; int n, s, k, D; int cmp(node p, node q)
{
if(p.R != q.R)
return p.R < q.R;
return p.L < q.L;
} bool Judge(int d)
{
for(int i=; i<=n; i++)
{
if(a[i].y + d > D)
return false;
}
met(b, );
for(int i=; i<=n; i++)
{
double y = a[i].y + d*1.0;
double x = sqrt(1.0*D*D - y*y);
b[i].L = a[i].x - x;
b[i].R = a[i].x + x;
}
sort(b+, b+n+, cmp);
int ans = ;
double R = b[].R;
for(int i=; i<=n; i++)
{
if(b[i].L > R)
{
ans ++;
R = b[i].R;
}
}
return ans <= s;
} int main()
{
int T, t = ;
scanf("%d", &T);
while(T--)
{
scanf("%d %d %d %d", &k, &n, &s, &D);
for(int i=; i<=n; i++)
{
scanf("%d %d", &a[i].x, &a[i].y);
a[i].y -= k;
}
int L = , R = D, ans = -;
while(L <= R)
{
int Mid = (L+R)/;
if(Judge(Mid))
{
ans = Mid;
L = Mid + ;
}
else
R = Mid - ;
}
printf("Case %d: ", t++);
if(ans == -)
puts("impossible");
else
printf("%d\n", ans);
}
return ;
}

LightOj1383 - Underwater Snipers(贪心 + 二分)的更多相关文章

  1. poj 2782 Bin Packing (贪心+二分)

    F - 贪心+ 二分 Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu   Description ...

  2. Card Game Cheater(贪心+二分匹配)

    Card Game Cheater Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  3. The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - F 贪心+二分

    Heap Partition Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge A sequence S = { ...

  4. 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II

    题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每 ...

  5. Codeforces Round #768 (Div. 2) D. Range and Partition // 思维 + 贪心 + 二分查找

    The link to problem:Problem - D - Codeforces   D. Range and Partition  time limit per test: 2 second ...

  6. UVALive 5000 Underwater Snipers --二分

    题意:一条河岸线y=k,y>k区域有n个敌人,现在要在y<=k区域布置S个狙击手,狙击手的狙击范围为距离自己半径为D的圆内,问满足能够狙死所有的敌人的情况下,离河岸线最近的那个狙击手的离河 ...

  7. Codeforces Round #307 (Div. 2) C. GukiZ hates Boxes 贪心/二分

    C. GukiZ hates Boxes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/ ...

  8. UVA 714 Copying Books 最大值最小化问题 (贪心 + 二分)

      Copying Books  Before the invention of book-printing, it was very hard to make a copy of a book. A ...

  9. P1182 数列分段`Section II`(贪心+二分, 好题)

    这道题让我见识了二分的新姿势.本来,我是二分的位置的. 思路:直接二分答案x, 关键是检验函数的写法: 先用前缀和 a[i....], 看满足多少段满足 a[ j ]-a[ i ]<=x; 的注 ...

随机推荐

  1. 【BZOJ】1076: [SCOI2008]奖励关(状压dp+数学期望)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1076 有时候人蠢还真是蠢.一开始我看不懂期望啊..白书上其实讲得很详细的,什么全概率,全期望(这个压 ...

  2. LIS+LCS+LCIS

    PS:本篇博文均采用宏#define FOR(i, a, n) for(i = a; i <= n; ++i) LIS:最长上升子序列 废话不多说:http://baike.baidu.com/ ...

  3. idea_IDEA跑Tomcat异常

    IDEA跑Tomcat异常 具体异常如下 Artifact :war exploded: Server is not connected. Deploy is not avail 根据别人的回答,去掉 ...

  4. mysql中INSTR函数的用法

    mysql中INSTR函数的用法 INSTR(字段名, 字符串) 这个函数返回字符串在某一个字段的内容中的位置, 没有找到字符串返回0,否则返回位置(从1开始) SELECT * FROM tblTo ...

  5. JavaScript验证正则表达式大全

    JavaScript验证正则表达式大全,搜集最全的JavaScript验证正则表达式,开始查看吧,这里的都是正则表达式的例子,具体和函数结合的使用方法,还请查看下篇文章<JavaScript使用 ...

  6. salt-ssh使用

    salt-ssh 是 0.17.0 新出现的一个功能,一听这名字就知道它是依赖 ssh 来进行远程命令执行的工具,好处就是你不需要在客户端安装 minion,也不需要安装 master(直接安装 sa ...

  7. pox目录中的交换机mac地址学习模块 l2_multi源码

    # Copyright 2012-2013 James McCauley # # Licensed under the Apache License, Version 2.0 (the "L ...

  8. jQuery 判断多个 input file 都不能为空

    例如有两个图片上传的 input,都必须上传图片: html 选择文件 1 :<input type="file" name="myfile[]" cla ...

  9. 1Web语言:开始了解HTML

    HTML是hybertext markup language的缩写,用来告诉浏览器网页的结构和内容.HTML的所有工作都是关于结构的,而不是外观.CSS是级联样式表(Cascading Style S ...

  10. P1434 滑雪

    水题,记忆化搜索,队列bfs均可 我们定义f[i][j]为到(i, j)的最长路径.然后就不难得出状态转移方程,然后使用无脑dfs,或者有脑递推都是可以的. #include <bits/std ...