Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
枚举终点 拆点限制流量#include<stdio.h> #include<iostream> #include<queue> #include<math.h> #include<string.h> #include<cmath> #define INF 100000000 #define N 2005 using namespace std; int sum,tot,list[N],listt[N],deep[N],n,mark[N]; double d; struct dian { int date,value,next; }cun[2000005]; struct bian { int x,t; }old,xin; struct ice { double x,y; int flag,k; }cc[505]; void add(int a,int b,int c) { cun[++tot].date=b; cun[tot].value=c; cun[tot].next=list[a]; list[a]=tot; cun[++tot].date=a; cun[tot].value=0; cun[tot].next=list[b]; list[b]=tot; } int BFS(int s,int t,int n) { xin.x=s; xin.t=0; //printf("!\n"); queue<bian>Q; Q.push(xin); memset(deep,255 ,sizeof(deep)); deep[s]=0; while(!Q.empty()) { old=Q.front(); Q.pop(); for(int k=list[old.x];k;k=cun[k].next) { int c=cun[k].value; xin.x=cun[k].date; // printf("%d\n",xin.x); xin.t=old.t+1; // printf("%d\n",deep[xin.x]); if(deep[xin.x]!=-1||c==0) { continue;} deep[xin.x]=xin.t; Q.push(xin); } } for(int i=0;i<=n;i++) listt[i]=list[i]; return deep[t]!=-1 ; } int mmin(int a,int b) { if(a<b) return a; else return b; } int DFS(int s,int t,int min) { if(s==t) return min; int neww=0; for(int k=listt[s];k;k=cun[k].next) { listt[s]=k; int c=cun[k].value; int date=cun[k].date; if(c==0||deep[date]!=deep[s]+1) continue; int m=DFS(date,t,mmin(c,min-neww)); neww+=m; cun[k].value-=m; cun[k^1].value+=m; if(neww==min) break; } if(neww==0) deep[s]=0; return neww; } int dinic(int s,int t,int n) { int num=0; // printf("%d\n",BFS(s,t,n)); while(BFS(s,t,n)) { // printf("!\n"); num+=DFS(s,t,INF); } return num; } double juli(double x1,double y1,double x2,double y2) { double k=1.0*(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)*1.0; return sqrt(k); } int slove(int x) { memset(list,0,sizeof(list)); tot=1; int s=2*n+10,t=s+1; for(int i=1;i<=n;i++) { if(cc[i].flag) { add(s,i,cc[i].flag); } add(i,i+n,cc[i].k); } for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) { if(juli(cc[i].x,cc[i].y,cc[j].x,cc[j].y)<d) { add(i+n,j,INF); add(j+n,i,INF); } } //add(x+n,t,INF); int k=dinic(s,x,s+10); // printf("%d\n",k); return k==sum; } int main() { int T; scanf("%d",&T); while(T--) { sum=0; memset(mark,0,sizeof(mark)); scanf("%d%lf",&n,&d); for(int i=1;i<=n;i++) { scanf("%lf%lf%d%d",&cc[i].x,&cc[i].y,&cc[i].flag,&cc[i].k); sum+=cc[i].flag; } int k=1,flag=0; for(int i=1;i<=n;i++) { if(slove(i)) { mark[k++]=i-1; flag=1;} } for(int i=1;i<k;i++) printf("%d ",mark[i]); if(!flag) printf("-1"); printf("\n"); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator