题目链接: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. 移动互联网终端的touch事件,touchstart, touchend, touchmove

    如果我们允许用户在页面上用类似桌面浏览器鼠标手势的方式来控制WEB APP,这个页面上肯定是有很多可点击区域的,如果用户触摸到了那些可点击区域怎么办呢??诸如智能手机和平板电脑一类的移动设备通常会有一 ...

  2. java第一节课

    1.安装 2.编写java程序 首先,新建一个文本文档:把后缀改成.java,然后起一个文件名,要是英文的,如:Hello. 然后,编辑,代码如下: class Hello { public stat ...

  3. Linux kernel perf_swevent_init Local root Exploit

    64位上编译 另外修改了原Exploit的一个错误 第76行 把     uint64_t *p = (void *) ¤t[i]; 改成       uint64_t *p = (void *) & ...

  4. CSV to XLSX (专用)

    $csvFile = "F:\ACL\HZ ACL\ACL-APAC.CSV" $path = "F:\ACL\HZ ACL\ACL-APAC.XLSX" $r ...

  5. 【iCore3 双核心板】例程二十八:FSMC实验——读写FPGA

    实验指导书及代码包下载: http://pan.baidu.com/s/1gerjjxh iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...

  6. Win7 桌面应用图标不见了

    taskkill /im explorer.exe /f cd /d %userprofile%\appdata\local del iconcache.db /a start explorer.ex ...

  7. pod 安装 Masonry 遇到问题

    pod 导入第三方库 Masonry: 在工程masonryTest的文件下新建一个Podfile文件 编辑如下内容: platform :ios, '8.0'xcodeproj 'mansoryTe ...

  8. ORA-01791: 不是 SELECTed 表达式

    Oracle 9i数据库,执行下面语句出现错误“ORA-01791: 不是 SELECTed 表达式”:select distinct t.name from auth_employee t orde ...

  9. flowvisor test(1)

    参考: Flowvisor 入门 杨帅老师:mininet+FlowVisor+ODL环境搭建及实验1 安装: 参考: 1.Flowvisor安装 2.Mininet安装 3.官网,Floodligh ...

  10. PHP+jQuery 列表分页类 ( 支持 url 分页 / ajax 分页 )

    /* ******* 环境:Apache2.2.8 ( 2.2.17 ) + PHP5.2.6 ( 5.3.3 ) + MySQL5.0.51b ( 5.5.8 ) + jQuery-1.8.3.mi ...