Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求大牛相助!!无限wr中!!为什么!!

Posted by 120705008 at 2014-08-15 21:38:30 on Problem 3498
#include<iostream>
using namespace std;
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<stack>
#include<algorithm>

#define MAXM 300*300
#define MAXN 300
#define oo 0x7fffffff

struct Dinic  
{  
      struct node   
      {  
             int x,y,c,next;  
      }line[MAXM];     
      int Lnum,_next[MAXN],dis[MAXN];  
      void initial(int n)   
      {  
             for (int i=0;i<=n;i++) _next[i]=-1;  
             Lnum=-1;  
      }   
      void addline(int x,int y,int c)  
      {  
             line[++Lnum].next=_next[x],_next[x]=Lnum;  
             line[Lnum].x=x,line[Lnum].y=y,line[Lnum].c=c;  
             line[++Lnum].next=_next[y],_next[y]=Lnum;  
             line[Lnum].x=y,line[Lnum].y=x,line[Lnum].c=0;               
      }  
      bool BFS(int s,int e)  
      {   
             queue<int> Q;  
             while (!Q.empty()) Q.pop();  
             memset(dis,0,sizeof(dis));  
             dis[s]=1;  
             Q.push(s);  
             while (!Q.empty())  
             {  
                   int h,k;  
                   h=Q.front(),Q.pop();  
                   if (h==e) return dis[e];  
                   for (k=_next[h];k!=-1;k=line[k].next)  
                      if (line[k].c && !dis[line[k].y])  
                         dis[line[k].y]=dis[h]+1,Q.push(line[k].y);                   
             }   
             return false;  
      }  
      int dfs(int x,int flow,int e)    
      {       
             if (x==e) return flow;     
             int temp,cost=0;    
             for (int k=_next[x];k!=-1;k=line[k].next)    
             if (line[k].c && dis[line[k].y]==dis[x]+1)    
             {    
                    temp=dfs(line[k].y,min(flow-cost,line[k].c),e);     
                    if (temp)    
                    {    
                           line[k].c-=temp,line[k^1].c+=temp;    
                           cost+=temp;    
                           if (flow==cost) return cost;    
                    }else dis[line[k].y]=-1;    
             }    
             return cost;    
      }    
      int MaxFlow(int s,int e)  
      {  
             int MaxFlow=0;  
             while (BFS(s,e)) 
                MaxFlow+=dfs(s,oo,e);   
             return MaxFlow;  
      }  
}T;   

double d(int x,int y,int x1,int y1)
{
       double a=(x-x1)*(x-x1)*1.0;
       double b=(y-y1)*(y-y1)*1.0;
       return sqrt(a+b);
}

double dis[220][220];

int main()
{
    int t;
    scanf("%d",&t);
    while (t--)
          {
          int n,sum=0,i,j,k;
          double D;
          int g[220][4];
          //cin >> n >> D;
          scanf("%d %lf",&n,&D);
          for (i=1;i<=n;++i)
              {
              scanf("%d %d %d %d",&g[i][0],&g[i][1],&g[i][2],&g[i][3]);
              sum+=g[i][2];
              }
              
          for (i=1;i<=n;++i)
              for (j=i+1;j<=n;++j)
                  dis[i][j]=dis[j][i]=d(g[i][0],g[i][1],g[j][0],g[j][1]);
                  
          int flag=0;
          int N=2*n+1;
          
          for (i=1;i<=n;++i)
              {
              T.initial(N);
              for (j=1;j<=n;++j) 
                  {
                  T.addline(0,j,g[j][2]);
                  T.addline(j,j+n,g[i][3]);
                  }
              
              
              for (j=1;j<=n;++j)
                  for (k=j+1;k<=n;++k)
                      if (dis[j][k]<=D)
                         {T.addline(n+j,k,oo);T.addline(n+k,j,oo);}
              
              if (T.MaxFlow(0,i)==sum)
                 {
                 if (flag==0) printf("%d",i-1);
                 else printf(" %d",i-1);
                 flag=1;
                 }
              }
          if (!flag) printf("-1\n");
              else printf("\n");
          }
    return 0;
} 

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator