hdu 3622 Bomb Game(二分+2-SAT)

时间:2022-08-29 23:40:21

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;
}

  

hdu 3622 Bomb Game(二分+2-SAT)的更多相关文章

  1. HDU 3622 Bomb Game&lpar;二分&plus;2SAT&rpar;

    题意:有一个游戏,有n个回合,每回合可以在指定的2个区域之一放炸弹,炸弹范围是一个圈,要求每回合的炸弹范围没有重合.得分是炸弹半径最小的值.求可以得到的最大分数. 思路:二分+2SAT. 二分炸弹范围 ...

  2. HDU - 3622 Bomb Game&lpar;二分+2-SAT&rpar;

    题目大意:玩一个放炸弹游戏,有N次放炸弹的机会,每次放炸弹时,你都有两个位置能够选择.问怎样放炸弹,能使爆炸的炸弹的半径的最小值最大(炸弹爆炸半径能够控制,可是爆炸形成的圈不能有重叠部分) 解题思路: ...

  3. HDU 3622 Bomb Game&lpar;2-sat&rpar;

    HDU 3622 Bomb Game 题目链接 题意:求一个最大半径,使得每一个二元组的点任选一个,能够得到全部圆两两不相交 思路:显然的二分半径,然后2-sat去判定就可以 代码: #include ...

  4. HDU 3622 Bomb Game(二分&plus;2-SAT)

    Bomb Game Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. hdu 3622 Bomb Game【二分&plus;2-SAT&plus;tarjan】

    用read()会挂 二分半径,显然最优的是所有原都用这个最小半径,然后2-SAT把相交的圆建图,跑tarjan判一下可行性即可 #include<iostream> #include&lt ...

  6. HDU 3622 Bomb Game(2-sat)

    Bomb Game Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  7. HDU 3622 Bomb Game

    Description \(n\) 个炸弹,每个炸弹有两个放置点,可以任选一个,问你最大的半径是多少. Sol 二分+2-SAT+Tarjan. 首先二分一下答案.然后就成了一个2-SAT问题. 建模 ...

  8. hdu 3622&lpar;二分&plus;2-sat判断可行性&rpar;

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3622 思路:二分是容易想到的,由于题目中有明显的矛盾关系,因此可以用2-sat来验证其可行性.关键是如 ...

  9. HDU 5934 Bomb(炸弹)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

随机推荐

  1. Centos搭建Python&plus;Nginx&plus;Tornado&plus;Mysql环境&lbrack;转载&rsqb;

    Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行.由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大型的入 ...

  2. paip&period;检测信用卡账单数据的正确性算法

    paip.检测信用卡账单数据的正确性算法 主要3点: //1.重点检测.大钱记录 //2.检测遗漏记录 //3.排除双唇记录. //4.试着cls share,改变错误的cls. 作者Attilax ...

  3. iOS 加载图片选择imageNamed 方法还是 imageWithContentsOfFile?

      Apple官方的文档为生成一个UIImage对象提供了两种方法: 1. imageNamed,其参数为图片的名字: 2. imageWithContentsOfFile,其参数也是图片文件的路径. ...

  4. iOS组件化思路-大神博客研读和思考

    一.大神博客研读 随着应用需求逐步迭代,应用的代码体积将会越来越大,为了更好的管理应用工程,我们开始借助CocoaPods版本管理工具对原有应用工程进行拆分.但是仅仅完成代码拆分还不足以解决业务之间的 ...

  5. &ast; 类描写叙述:字符串工具类 类名称:String&lowbar;U

    /****************************************** * 类描写叙述:字符串工具类 类名称:String_U * ************************** ...

  6. 简述layui前端ui框架的使用

    官方网址:https://www.layui.com/demo/upload.html

  7. 不定高元素的高度transition动画实现

    分析文档描述 CSS 支持动画的属性中的 height 属性如下: height :yes, as a length, percentage or calc() 即:当 height 的值是 leng ...

  8. Node&period;js 种子下载器

    Node.js 种子下载器 庆祝 2018 国庆,制作了一个 Node.js 的种子下载器.爬取页面,根据页面的链接,破解另外一个网站,下载种子文件.项目比较简单,爬取页面没有使用任何爬虫框架.项目源 ...

  9. &lbrack;C&plus;&plus;&rsqb;PAT乙级1002&period;写出这个数&lpar;20&sol;20&rpar;

    /* 1002. 写出这个数 (20) 读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值.这里保证n小于10^100. ...

  10. hive有关函数

    1.窗口函数2015年4月份购买过的顾客及总人数 select distinct name,count(1) over() as cnt from test_window_yfwhere substr ...