您的位置:首页 > 其它

hlg1481 Attack of the Giant n-pus【二分+二分图】

2014-09-19 08:55 246 查看
Attack of the Giant n-pus
Time Limit: 2000 MSMemory Limit: 65536 K
Total Submit: 71(6 users)Total Accepted: 8(5 users)Rating:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;

const int maxn = 101;

int n, p;

struct Edge
{
int to,next;
}e[10002];
int head[maxn];
int tot;
void add(int s,int u)
{
e[tot].to = u;
e[tot].next = head[s];
head[s] = tot++;
}

double xi[maxn], yi[maxn], vi[maxn];
double xj[maxn], yj[maxn];
double dist[maxn][maxn];

int vis[maxn], Link[maxn];

bool Find(int u) {
for(int i = head[u]; i; i = e[i].next) {
int v = e[i].to;
if(!vis[v]) {
vis[v] = 1;
if(Link[v] == -1 || Find(Link[v]) ) {
Link[v] = u;
return true;
}
}
}
return false;
}

bool Match() {
memset(Link, -1, sizeof(Link));
for(int i = 1; i <= n; i++) {
memset(vis, 0, sizeof(vis));
if(!Find(i) ) return false;
}
return true;
}

double Dist(double x1, double y1, double x2, double y2) {
double xx = x1 - x2;
double yy = y1 - y2;
return sqrt(xx * xx + yy * yy );
}

bool check(double mid) {
tot = 1; memset(head, 0, sizeof(head));
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= p; j ++) {
if(dist[i][j] < mid) {
add(i, j);
}
}
}
if(Match()) {
return true;
}
return false;
}

const double wucha = 0.0000000001;

int main() {
double xc, yc, vc;
double xh, yh;
int t;
//freopen("test.txt","r",stdin);
scanf("%d",&t);
while(t--) {
scanf("%d %d",&n, &p);
scanf("%lf %lf %lf", &xc, &yc, &vc);
for(int i = 1;  i <= p; i++) {
scanf("%lf %lf %lf", &xi[i], &yi[i], &vi[i]);
}
scanf("%lf %lf", &xh, &yh);
for(int i = 1; i <= n; i++) {
scanf("%lf %lf", &xj[i], &yj[i]);
}
double low = 0, high = 0;
for(int i = 1;i <= n; i++) {
for(int j = 1; j <= p; j++) {
dist[i][j] = Dist(xj[i], yj[i], xi[j], yi[j]) * 1.0 / vi[j];
if(dist[i][j] > high) high = dist[i][j];
}
}
while(low < high) {
double mid = (low + high) * 0.5;
if(!check(mid)) {
low = mid + wucha;
} else {
high = mid - wucha;
}
}
double ans = high + wucha;
ans += (Dist(xc, yc, xh, yh) / vc);
printf("%.9lf\n", ans);
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐