标签:game hdu pac amp origin 注意 tps == can
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N = 5e3 + 9;
const int M = N*2*N;
int h[N], ne[M], to[M], idx;
void add(int u, int v) {
ne[idx] = h[u], to[idx] = v, h[u] = idx++;
}
int dfn[N], low[N], times;
int sz[N], id[N], scc_cnt;
int stk[N], instk[N], top;
void tarjan(int u) {
dfn[u] = low[u] = times++;
stk[++top] = u;
instk[u]= 1;
for (int i = h[u]; ~i; i = ne[i]) {
int v = to[i];
if (!dfn[v]) {
tarjan(v);
low[u] = min(low[u], low[v]);
} else if (instk[v]) {
low[u] = min(low[u], dfn[v]);
}
}
if (low[u] == dfn[u]){
scc_cnt++;
while (1) {
int v = stk[top];
top--;
instk[v] = 0;
id[v] = scc_cnt;
sz[scc_cnt] ++;
if (v == u)break;
}
}
}
int n, m;
struct Point {
double x, y;
Point() : x(), y() {}
Point (double x, double y):x(x), y(y){}
Point operator-(Point a) {
return Point(x - a.x, y - a.y);
}
double dis() {
return (x*x + y*y);
}
}p[3][N];
bool check(double mid) {
memset(h, -1, sizeof h);
idx = 0;
memset(dfn, 0, sizeof dfn);
scc_cnt = 0;
times = 0;
for (int i = 1; i <= n; i ++) {
for (int j = 1; j <= n; j ++) {
if (i == j)continue;
for (int k = 0; k < 2; k ++) {
for (int kk = 0; kk < 2; kk ++) {
Point v1 = p[k][i] - p[kk][j];
if (v1.dis() < mid * mid) {
add(i +k*n, j+ (kk^1) * n);//建边的时候要注意,必须是如果当前不满足,那么就连对面。
}
}
}
}
}
for (int i = 1; i <=2* n; i ++) {
if (!dfn[i]) {
tarjan(i);
}
}
for (int i = 1; i <= n; i ++) {
if (id[i] == id[i + n]) {
return 0;
}
}
return 1;
}
void solve() {
for (int i = 1; i <= n; i ++) {
scanf("%lf%lf%lf%lf",&p[0][i].x, &p[0][i].y, &p[1][i].x, &p[1][i].y);
}
double l = 0, r = 20000;
int TT = 40;
while (l < r && TT--) {
double mid = (l + r)/2;
if (check(mid)) {
l = mid + 0.0000001;
} else r = mid;
}
printf("%.2f\n", l*0.5);
}
int main() {
while (~scanf("%d", &n)) {
solve();
}
}
标签:game hdu pac amp origin 注意 tps == can
原文地址:https://www.cnblogs.com/Xiao-yan/p/14643438.html