【HDU 3622】Bomb Game
http://acm.hdu.edu.cn/showproblem.php?pid=3622
二分答案转化成2-sat问题。
上午测试时总想二分后把它转化成最大点独立集但是不会写最大点独立集暴力又秘制写错所以就爆零啦~~~
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 503;
double x[N << 1], y[N << 1], dis[N << 1][N << 1];
double sqr(double x) {return x * x;}
struct node {int nxt, to;} E[N * N];
int bel[N << 1], dfn[N << 1], low[N << 1], dfn_cnt;
int st[N << 1], top = 0, cnt, point[N << 1], dn, n, col_tot;
bool inst[N << 1];
void ins(int u, int v) {E[++cnt] = (node) {point[u], v}; point[u] = cnt;}
void tarjan(int u) {
dfn[u] = low[u] = ++dfn_cnt;
inst[st[++top] = u] = true;
if (u == 11) {
++u; --u;
}
for (int i = point[u]; i; i = E[i].nxt) {
if (!dfn[E[i].to]) tarjan(E[i].to), low[u] = min(low[u], low[E[i].to]);
else if (inst[E[i].to]) low[u] = min(low[u], dfn[E[i].to]);
}
if (dfn[u] == low[u]) {
++col_tot;
while (st[top] != u) {
inst[st[top]] = false;
bel[st[top--]] = col_tot;
}
inst[u] = false; bel[u] = col_tot; --top;
}
}
bool can(double num) {
cnt = 0;
memset(point, 0, sizeof(int) * dn);
for (int i = 0; i < dn; ++i)
for (int j = i + 1; j < dn; ++j)
if (j - i != n && dis[i][j] < num)
ins(i, (j + n) % dn), ins(j, (i + n) % dn);
dfn_cnt = col_tot = 0;
memset(dfn, 0, sizeof(int) * dn);
for (int i = 0; i < dn; ++i)
if (dfn[i] == 0) tarjan(i);
for (int i = 0; i < n; ++i)
if (bel[i] == bel[i + n])
return false;
return true;
}
int main() {
while (~scanf("%d", &n)) {
for (int i = 0; i < n; ++i)
scanf("%lf%lf%lf%lf", x + i, y + i, x + n + i, y + n + i);
dn = n << 1;
for (int i = 0; i < dn; ++i)
for (int j = i + 1; j < dn; ++j)
if (j - i != n)
dis[i][j] = dis[j][i] = sqrt(sqr(x[i] - x[j]) + sqr(y[i] - y[j]));
double left = 0, right = 22000, mid;
while (right - left > 1e-5) {
mid = (left + right) / 2;
if (can(mid)) left = mid;
else right = mid;
}
printf("%.2lf\n", left / 2);
}
return 0;
}
【HDU 3622】Bomb Game的更多相关文章
- 【HDU 3555】 Bomb
[题目链接] 点击打开链接 [算法] 数位DP [代码] #include<bits/stdc++.h> using namespace std; #define MAXL 15 type ...
- 【HDU 5934】Bomb(强连通缩点)
Problem Description There are N bombs needing exploding. Each bomb has three attributes: exploding r ...
- 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题
[HDU 3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...
- 【HDU 5647】DZY Loves Connecting(树DP)
pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...
- -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】
[把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...
- 【HDU 2196】 Computer(树的直径)
[HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...
- 【HDU 2196】 Computer (树形DP)
[HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...
- 【HDU 5145】 NPY and girls(组合+莫队)
pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...
- 【hdu 1043】Eight
[题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1043 [题意] 会给你很多组数据; 让你输出这组数据到目标状态的具体步骤; [题解] 从12345 ...
随机推荐
- HDU 1087 Super Jumping! Jumping! Jumping! --- DP入门之最大上升子序列
题目链接 DP基础题 求的是上升子序列的最大和 而不是最长上升子序列LIS DP[i]表示以a[i]结尾所能得到的最大值 但是a[n-1]不一定是整个序列能得到的最大值 #include <bi ...
- dot.js使用心得
一.dot.js介绍 最近用到的数据模板引擎有很多,今天讲的doT.js也是其中一种. doT.js的特点是体积小,速度快,并且不依赖其他插件. 官网下载:http://olado.github.io ...
- Python模块学习 - Argparse
argparse模块 在Python中,argparse模块是标准库中用来解析命令行参数的模块,用来替代已经过时的optparse模块.argparse模块能够根据程序中的定义从sys.argv中解析 ...
- 通用套接字选项和TCP套接字选项
1. 套接字选项函数原型: #include <sys/socket.h> int getsockopt(int sockfd, int level, int optname, void ...
- python基础===codecs打开文件,解决文件编码格式的问题
codecs https://docs.python.org/3/library/codecs.html 我们经常用open打开文件的时候会出现各式各样的错误,编码格式的问题,等等~真的很烦 现在尽量 ...
- python基础===继承
编写类时,并非总是要从空白开始.如果你要编写的类是另一个现成类的特殊版本,可使用继承.一个类继承另一个类时,它将自动获得另一个类的所有属性和方法:原有的类称为父类,而新类称为子类.子类继承了其父类的所 ...
- RemoteBox 1.6 发布,VirtualBox 管理工具
RemoteBox 1.6 发布,VirtualBox 管理工具 http://www.lupaworld.com/article-230113-1.html 安装VirtualBox Extensi ...
- gcc -rpath 指定动态库路径
gcc -rpath 指定动态库路径 http://blog.csdn.net/v6543210/article/details/44809405
- RSA加密解密与加签验签
RSA公钥加密算法是1977年由罗纳德·李维斯特(Ron Rivest).阿迪·萨莫尔(Adi Shamir)和伦纳德·阿德曼(Leonard Adleman)一起提出的.1987年7月首次在美国公布 ...
- js刷新页面代码
第一种: location.reload() 第二种: location.replace(location.href) 第三种: history.go() 第四种: location=location ...