标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 885 Accepted Submission(s): 409
#include <stdio.h> #include <algorithm> #include <queue> #include <string.h> #include <math.h> using namespace std; const int N = 350; const int INF = 999999999; int cap[N][N]; int flow[N]; int pre[N]; int n; struct Node{ int x,y,r; double f; }node[N]; double dis(Node a,Node b){ return sqrt(1.0*((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y))); } int bfs(int src,int des){ queue<int> q; for(int i=1;i<=des;i++){ pre[i]=-1; } pre[src]=0; flow[src]=INF; q.push(src); while(!q.empty()){ int u = q.front(); q.pop(); if(u==des) break; for(int i=1;i<=des;i++){ if(i!=src&&cap[u][i]>0&&pre[i]==-1){ pre[i] = u; flow[i] = min(cap[u][i],flow[u]); q.push(i); } } } if(pre[des]==-1) return -1; return flow[des]; } int max_flow(int src,int des){ int ans = 0,increaseRoad; while((increaseRoad=bfs(src,des))!=-1){ int k = des; while(k!=src){ cap[pre[k]][k]-=increaseRoad; cap[k][pre[k]]+=increaseRoad; k = pre[k]; } ans+=increaseRoad; } return ans; } int cmp(Node a,Node b){ return a.f<b.f; } void build(){ scanf("%d",&n); memset(cap,0,sizeof(cap)); for(int i=1;i<=n;i++){ scanf("%lf%d%d%d",&node[i].f,&node[i].x,&node[i].y,&node[i].r); } sort(node+1,node+n+1,cmp); for(int i=1;i<=n;i++){ for(int j=i+1;j<=n;j++){ if(i!=j&&dis(node[i],node[j])<=(node[i].r+node[j].r)){ cap[i][j]=1; } } } } int main(){ int tcase; scanf("%d",&tcase); while(tcase--){ build(); int t = max_flow(1,n); if(t>=2) printf("Game is VALID\n"); else printf("Game is NOT VALID\n"); } }
标签:
原文地址:http://www.cnblogs.com/liyinggang/p/5550910.html