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; 的注 ...
随机推荐
- Codeforces Round #208 (Div. 2) B Dima and Text Messages
#include <iostream> #include <algorithm> #include <string> using namespace std; in ...
- Odoo ir actions 分析
源代码位置:openerp/addons/base/ir/ir_actions.py 根类型:ir.actions.actions class actions(osv.osv): _name = 'i ...
- Odoo Two ways to pop warning infomation
1. raise ValueError(_('title'),_('message')) 2.raise except_orm(_('title'),_('message'))
- shell if判断语句
测试脚本是否有语法错误: sh -n 脚本名 一.if语句: 二.逻辑运算解析: -f 判断文件是否存在 -d 判断目录是否存在 -eq 判断是否相等 -ne 判断是否不相等 -lt 小于 -g ...
- Scala:使用Sublime开发Scala
Scala:使用Sublime开发Scala 第一步:[Tools][Build System][New Build System] 第二步:在打开的新文件中输入: { //"cmd&quo ...
- Html - 瀑布流
瀑布流,又称瀑布流式布局.是比较流行的一种网站页面布局,视觉表现为参差不齐的多栏布局,随着页面滚动条向下滚动,这种布局还会不断加载数据块并附加至当前尾部.最早采用此布局的网站是Pinterest,逐渐 ...
- [转]一步一步asp.net_购物车订单与支付宝
本文转自:http://www.cnblogs.com/mysweet/archive/2012/05/19/2508534.html 最近这几天很忙,一边忙着准备一堆课程设计(8门专业课.....伤 ...
- Javascript 笔记与总结(2-17)事件委托
[例]五子棋,单次点击为黑色,偶次点击为白色.e.target 的用法 <!DOCTYPE html> <html lang="en"> <head& ...
- js判断时间差
//var startDate = "2015-09-09"; //var endDate = "2015-09-08"; var startDate = &q ...
- phpstorm8注册码
phpstorm8注册码 phpstorm 8 注册码 用户名:Learn Programming License key:(包括LICENSE BEGIN和LICENSE END部分) ==== ...