LightOj1383 - Underwater Snipers(贪心 + 二分)
题目链接: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(贪心 + 二分)的更多相关文章
- poj 2782 Bin Packing (贪心+二分)
F - 贪心+ 二分 Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description ...
- Card Game Cheater(贪心+二分匹配)
Card Game Cheater Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 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 = { ...
- 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II
题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每 ...
- 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 ...
- UVALive 5000 Underwater Snipers --二分
题意:一条河岸线y=k,y>k区域有n个敌人,现在要在y<=k区域布置S个狙击手,狙击手的狙击范围为距离自己半径为D的圆内,问满足能够狙死所有的敌人的情况下,离河岸线最近的那个狙击手的离河 ...
- 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/ ...
- UVA 714 Copying Books 最大值最小化问题 (贪心 + 二分)
Copying Books Before the invention of book-printing, it was very hard to make a copy of a book. A ...
- P1182 数列分段`Section II`(贪心+二分, 好题)
这道题让我见识了二分的新姿势.本来,我是二分的位置的. 思路:直接二分答案x, 关键是检验函数的写法: 先用前缀和 a[i....], 看满足多少段满足 a[ j ]-a[ i ]<=x; 的注 ...
随机推荐
- BZOJ3680 : 吊打XXX
本题就是找一个受力平衡的点 我们一开始假设这个点是(0,0) 然后求出它受到的力,将合力正交分解后朝着合力的方向走若干步,并不断缩小步长,一步步逼近答案 #include<cstdio> ...
- chrome developer tool 调试技巧
这篇文章是根据目前 chrome 稳定版(19.0.1084.52 m)写的, 因为 google 也在不断完善chrome developer tool, 所以 chrome 版本不同可能稍有差别. ...
- 【wikioi】1108 方块游戏(模拟)
http://wikioi.com/problem/1108/ 这题有点变态,因为他根本没有策略! 还是说这题不是实时的?反正这题很变态,是在一个时间段同时消除所有的行列斜边,同一时间!!!!!! 所 ...
- [shell] if else以及大于、小于、等于逻辑表达式 [转]
本文也即<Learning the bash Shell>3rd Edition的第五章Flow Control之读书笔记,但我们将不限于此.flow control是任何编程语言中很常用 ...
- zabbix配置文件详解
Zabbix之配置文件详解 zabbix配置文件种类: zabbix_server配置文件zabbix_server.conf zabbix_proxy配置文件zabbix_proxy.conf ...
- 获取Dell,Lenovo电脑的保修期
2015-4-6写的代码(Dell), 不知道如何对报错进行友好化处理,于是采用了"非空"和"非空的补集"处理方式. $service = New-WebSer ...
- 如何搭建redis扩展-Yii中文网
原文链接: 如何搭建redis扩展http://www.yii-china.com/post/detail/43.html 安装redis扩展: 1.通过composer进行安装,到项目根目录cmd运 ...
- Redis 笔记与总结2 String 类型和 Hash 类型
Linux 版本信息: cat /etc/issue 或cat /etc/redhat-release(Linux查看版本当前操作系统发行版信息) CentOS release 6.6 (Final) ...
- Guilty Gear Xrd 资源Rip(1)
资源破解 首先先要下载GGXrd的PS3游戏,用psarc.exe先把游戏解包 http://files.cnblogs.com/TracePlus/psarc.exe.zip 下载UMode ...
- javaWeb中struts开发——helloworld
1.新建一个web项目 2.选中project,右键,选择MyElcipse,选择add struts capab...添加struts支持,然后自己命名包 3.Struts在建立jsp时,标签要到 ...