Bomb Game

Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2951    Accepted Submission(s): 984

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
 
Source
 
Recommend
lcy

解题:对半径进行二分,用2-SAT看能不能找出一个可行方案.

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
const int MAXN = 205;
const int MAXM = 40005;
const double eps = 1e-5;
int n;
int head[MAXN];
struct node1{
int x,y;
}point[MAXN];
struct node {
int t,next;
}edge[MAXM];
int cnt;
void add(int u, int v) {
edge[cnt].t = v;
edge[cnt].next = head[u];
head[u] = cnt++;
}
int bfn[MAXN];
int low[MAXN];
int vis[MAXN];
int s[MAXN];
int sn;
void tarbfs(int u, int lay, int & scc_num) {
vis[u] = 1;
bfn[u] = low[u] = lay;
s[sn++] = u;
int i;
for (i = head[u]; i != -1; i = edge[i].next) {
int tmp = edge[i].t;
if (!vis[tmp])tarbfs(tmp, ++lay, scc_num);
if (vis[tmp] == 1)low[u] = min(low[u], low[tmp]);
}
if (low[u] == bfn[u]) {
scc_num++;
while (1) {
sn--;
vis[s[sn]] = 2;
low[s[sn]] = scc_num;
if (s[sn] == u)break;
}
}
}
int tarjan() {
int scc_num = 0;
int lay = 1;
int i;
sn = 0;
memset(vis, 0, sizeof(vis));
for (i = 0; i < 2 * n; i++) {
if (!vis[i])
tarbfs(i, lay, scc_num);
}
return scc_num;
}
double dist(node1 a, node1 b) {
return sqrt((double)(a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
bool solve() {
tarjan();
int i;
for (i = 0; i < n/2; i++) {
if (low[i<<1] == low[i<<1|1])
return false;
}
return true;
}
void build(double mid) {
int i,j;
cnt = 0;
memset(head, -1, sizeof(head));
for (i = 0; i < n - 2; i++) {
int t = i;
if (i & 1)
t += 1;
else
t += 2;
for (j = t; j < n; j++) {
if (dist(point[i], point[j]) < 2 * mid) {
add(i, j^1);
add(j, i^1);
}
}
}
} int main() {
// freopen("in.txt","r",stdin);
int i;
while (scanf("%d",&n) != EOF) {
for(i = 0; i < n; i++) {
scanf("%d %d %d %d",&point[i<<1].x, &point[i<<1].y, &point[i<<1|1].x, &point[i<<1|1].y);
}
n = 2 * n;
double L = 0;
double R = 40000;
while (R - L > eps) {
double mid = (L + R) / 2;
build(mid);
if (solve())
L = mid;
else
R = mid;
}
printf("%.2lf\n",L);
}
return 0;
}

  

最新文章

  1. 基于webdriver的jmeter性能测试-Selenium IDE
  2. 8、需求分析师要阅读的书籍 - IT软件人员书籍系列文章
  3. 九度oj 题目1087:约数的个数
  4. 北航 编译实践 PL/0文法
  5. spring mvc返回json字符串数据,只需要返回一个java bean对象就行,只要这个java bean 对象实现了序列化serializeable
  6. 监控windows服务,当服务停止后自动重启服务
  7. 重拾C,一天一点点_11
  8. python autopy
  9. hdu 1199 Color the Ball(离散化线段树)
  10. 【Linux&amp;amp;Unix--open/close/write/read系统调用】
  11. 20164301 Exp5 MSF基础应用
  12. 从零开始学习java(一)java基础语法
  13. 数据仓库分层ODS DW DM 主题 标签
  14. mac“打不开身份不明的开发者”
  15. springmvc入门(1)
  16. Java 在方法和作用域内的内部类
  17. Sony/索尼 NW-ZX300A ZX300 无损音乐播放器4.4口
  18. spark结构化数据处理:Spark SQL、DataFrame和Dataset
  19. xcode下build release版本号的.a库
  20. 51nod1254 最大子段和 V2 DP

热门文章

  1. [Maven]修改Maven的本地仓库路径
  2. Python导入自定义包或模块
  3. HTML5 History API实现无刷新跳转
  4. aar引用 no executable code found问题
  5. form表单的enter自动提交
  6. Linux disk_partition_dev_马士兵_note
  7. Android: R cannot be resolved to a varia...
  8. OpenSSL漏洞补救办法详解(转)
  9. Linux系统下如何查看已经登录用户
  10. JS 学习(四)对象