Bomb Game

Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5396    Accepted Submission(s): 1925

Problem Description
Robbie is playing an interesting computer game. The game field is an unbounded 2-dimensional region. There are N rounds in the game. At each round, the computer will give Robbie two places, and Robbie should choose one of them to put a bomb. The explosion area of the bomb is a circle whose center is just the chosen place. Robbie can control the power of the bomb, that is, he can control the radius of each circle. A strange requirement is that there should be no common area for any two circles. The final score is the minimum radius of all the N circles.
Robbie has cracked the game, and he has known all the candidate places of each round before the game starts. Now he wants to know the maximum score he can get with the optimal strategy.

 
Input
The first line of each test case is an integer N (2 <= N <= 100), indicating the number of rounds. Then N lines follow. The i-th line contains four integers x1i, y1i, x2i, y2i, indicating that the coordinates of the two candidate places of the i-th round are (x1i, y1i) and (x2i, y2i). All the coordinates are in the range [-10000, 10000].

 
Output
Output one float number for each test case, indicating the best possible score. The result should be rounded to two decimal places.

 
Sample Input
2
1 1 1 -1
-1 -1 -1 1
2
1 1 -1 -1
1 -1 -1 1
 
Sample Output
1.41
1.00
 
 
题目链接:HDU 3622
很明显的二分题,二分爆炸半径r使得被选中的炸弹的爆炸出的圆面积均没有相交(边缘可以重叠)即可。
代码:

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define LC(x) (x<<1)
#define RC(x) ((x<<1)+1)
#define MID(x,y) ((x+y)>>1)
#define CLR(arr,val) memset(arr,val,sizeof(arr))
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
typedef pair<int, int> pii;
typedef long long LL;
const double PI = acos(-1.0);
const double eps = 1e-5;
const int N = 110;
const int M = N * N * 4;
struct edge
{
int to, nxt;
edge() {}
edge(int _to, int _nxt): to(_to), nxt(_nxt) {}
};
pii P[N];
edge E[M];
int head[N << 1], tot;
int dfn[N << 1], low[N << 1], st[N << 1], belong[N << 1], ts, scc, top;
bitset < N << 1 > ins;
int n; void init()
{
CLR(head, -1);
tot = 0;
CLR(dfn, 0);
CLR(low, 0);
CLR(belong, 0);
ts = scc = top = 0;
ins.reset();
}
inline void add(int s, int t)
{
E[tot] = edge(t, head[s]);
head[s] = tot++;
}
void Tarjan(int u)
{
dfn[u] = low[u] = ++ts;
st[top++] = u;
ins[u] = 1;
int i, v;
for (i = head[u]; ~i; i = E[i].nxt)
{
v = E[i].to;
if (!dfn[v])
{
Tarjan(v);
low[u] = min(low[u], low[v]);
}
else if (ins[v]) low[u] = min(low[u], dfn[v]);
}
if (dfn[u] == low[u])
{
++scc;
do
{
v = st[--top];
ins[v] = 0;
belong[v] = scc;
}
while (u != v);
}
}
inline double cal(const pii &a, const pii &b)
{
return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second));
}
bool check(double r, int sz)
{
init();
int i, j;
for (i = 0; i < sz; i += 2)
{
for (j = i + 2; j < sz; ++j)
{
double dx = cal(P[i], P[j]);
if (dx < 2 * r)
{
add(i, j ^ 1);
add(j, i ^ 1);
}
}
}
for (i = 1; i < sz; i += 2)
{
for (j = i + 1; j < sz; ++j)
{
double dx = cal(P[i], P[j]);
if (dx < 2 * r)
{
add(i, j ^ 1);
add(j, i ^ 1);
}
}
}
for (i = 0; i < sz; ++i)
if (!dfn[i])
Tarjan(i);
for (i = 0; i < sz; ++i)
if (belong[i] == belong[i ^ 1])
return false;
return true;
}
int main(void)
{
int i;
while (~scanf("%d", &n))
{
for (i = 0; i < (n << 1); i += 2)
scanf("%d%d%d%d", &P[i].first, &P[i].second, &P[i | 1].first, &P[i | 1].second);
double L = 0, R = 10000 * 1.45;
double ans = 0;
while (R - L >= eps)
{
double mid = (L + R) / 2.0;
if (check(mid, n << 1))
{
L = mid;
ans = mid;
}
else
R = mid;
}
printf("%.2f\n", ans);
}
return 0;
}

最新文章

  1. 轻量级“集合”迭代器-Generator
  2. freebsd启动报错:My unqualified host name unkown...Sleeping for retry.
  3. Java设计模式 - 观察者模式
  4. Linux第二次学习笔记
  5. button改变背景与文字颜色
  6. Web服务器控件表
  7. 使用aspose.word两句代码将word转换为pdf
  8. [置顶] mysql中的set和enum类型的用法和区别
  9. 201521123098 JAVA课程设计
  10. Linux下Power Management开发总结
  11. pycharm中配置启动Django项目
  12. 微信开发者工具_小程序js文件后面的M代表什么
  13. 【AI】神经网络基本词汇
  14. Runtime单例模式类 -- 控制电脑关机
  15. 普通用户开放 sudo 权限
  16. Python入门 ---基础知识
  17. Cocos2d-x 3.2 打包Android平台APK
  18. 从VMware虚拟机安装到hadoop集群环境配置详细说明(第一期)
  19. linux:进程概念
  20. TCP与UDP的差别以及TCP三次握手、四次挥手

热门文章

  1. 【转】chrome浏览器的跨域设置——包括版本49前后两种设置
  2. 【转】浅谈Node.js单线程模型
  3. MacOS内核调试环境搭建
  4. android设备局域网中快速搜索之cling方式
  5. shell脚本,利用awk计算指定范围内的和。
  6. SummerVocation_Learning--java的自动打包与解包
  7. linux中管道(pipe)一谈
  8. linux下通过phpize为php在不重新编译php情况下安装模块memcache
  9. Cisco交换机与路由器命令总结
  10. PHP去掉字符串中的数字