【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 ...
随机推荐
- CodeForces 316D3 PE Lesson
time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standa ...
- 【NOIP】提高组2012 疫情控制
[题意]n个点的树,1为根,要求删除一些点使得截断根节点和所有叶子结点的路径(不能删根,可以删叶子).有m支军队在m个点上,每时刻所有军队可以走一步,最终走到的地方就是删除的点,求最短时间. [算法] ...
- 虽然UIImageView是UIScollView的子视图,但UIImageView左上角是contentOfSet的原点
虽然UIImageView是UIScollView的子视图,但UIImageView左上角是contentOfSet的原点 https://www.evernote.com/shard/s22 ...
- Network of Schools(POJ1326+有向图进行缩点)
题目链接:http://poj.org/problem?id=1236 题目: 题意:对于n个学校,对于一个系统传给某个学校,那么他会传给他得支援学校.从第二开始,每行给你多个数字,表示第i个学校可以 ...
- idea 导入 java json 包
1.java 项目导包 找到 External Libraries 下面的java版本包,在点击鼠标右键.直接找到jar路径全部选中导入即可.
- ipython notebook环境搭建
默认已经装好python基本环境,再进行下面步骤: 1. 下载安装IPython: c:>pip.exe install ipython 系统就会去网上寻找ipython的包, 进行下载及安装 ...
- Python学习笔记 - day10 - 正则表达式
正则表达式 字符串是编程时涉及到的最多的一种数据结构,对字符串进行操作的需求几乎无处不在.比如判断一个字符串是否是合法的Email地址,虽然可以编程提取@前后的子串,再分别判断是否是单词和域名,但这样 ...
- Linux的SMP,UMA,NUMA
SMP 是Symmetric Multi-Processing的意思,对称多处理器,一种多核结构,认为这些核是完全同构的,任务可以随便在任一个核上跑. UMA是Uniform Memory Acces ...
- MySQL的读写分离---主从复制、主主复制
1.复制是基于BinLog日志 存在三种日志格式:Statement:存储Sql语句,存储日志量是最小的.有可能复制不一致Row:存储event数据,存储日志量大,但是不能很直接进行读取:Mixed: ...
- python_day4学习笔记
一.内置函数