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

为什么RE了,求高人指点

Posted by liyaoshi1 at 2012-06-02 11:14:09 on Problem 2112
我用的是二分查找+ISAP求最大流,感觉不会RE啊
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
const int VMAX=233;
int K,C,M,V;
int p[3501],l=0;
int a[VMAX][VMAX],c[VMAX][VMAX],d[VMAX],pre[VMAX],sumd[VMAX];
void set()
{
    int t=V-1;
    memset(d,1,sizeof(d));
    memset(sumd,0,sizeof(sumd));
    queue<int> P;
    P.push(t);
    d[t]=0;
    sumd[0]=1;
    while(!P.empty())
    {
        int k=P.front(); P.pop();
        for(int i=0;i<V;i++)                 
            if(c[i][k]&&d[i]>=V)
            {
                P.push(i);
                d[i]=d[k]+1;
                sumd[d[i]]++;                    
            }                           
    }    
}
int find(int i)
{
    for(int j=0;j<V;j++)    
        if(c[i][j]&&d[i]==d[j]+1)
            return j;
    return -1;
}
int num(int i)
{
    int t=1000000000;
    for(int j=0;j<V;j++)    
        if(c[i][j]&&d[j]+1<t)
            t=d[j]+1;
    return (t==1000000000)?V:t;
}
int maxflow(int s,int t)//ISAP
{    
      set();
      int i=s,sumflow=0;
      while(d[s]<V)
      {
          int k=find(i);              
          if(k>=0)
          {
              pre[k]=i;
              i=k;
              if(i==t)        
              {
                  int flow=1000000000;
                  for(i=t;i!=s;i=pre[i])                
                      if(flow>c[pre[i]][i])
                          flow=c[pre[i]][i];
                  for(i=t;i!=s;i=pre[i])
                  {
                      c[pre[i]][i]-=flow;
                      c[i][pre[i]]+=flow;                      
                  }            
                  sumflow+=flow;
              }
          }    
          else
          {
              int x=num(i);    
              if(--sumd[d[i]]==0) break;
              d[i]=x;
              sumd[x]++;
              if(i!=s) i=pre[i];
          }                  
      }  
      return sumflow;
}
int check(int x)//构图 
{
    memset(c,0,sizeof(c));
    for(int i=0;i<K;i++)       
        for(int j=K;j<K+C;j++)
            if(a[i][j]<=x)
                c[i][j]=1;
    for(int i=0;i<K;i++)
        c[V-2][i]=M;
    for(int i=K;i<K+C;i++)
        c[i][V-1]=1;    
    int o=maxflow(V-2,V-1);
    if(o>=C) return 1;
    else return 0;
}
int main()
{
    cin>>K>>C>>M;    
    V=K+C;
    for(int i=0;i<V;i++)
        for(int j=0;j<V;j++)
        {
            cin>>a[i][j];
            if(a[i][j]==0) a[i][j]=1000000000;
        }    
    for(int k=0;k<V;k++)//Floyd
        for(int i=0;i<V;i++)
            for(int j=0;j<V;j++)
                if(a[i][k]+a[k][j]<a[i][j])
                    a[i][j]=a[i][k]+a[k][j];   
    V+=2;   
    int low,high;
    for(int i=0;i<K;i++) 
        for(int j=K;j<K+C;j++)
        {
            if(a[i][j]>high&&a[i][j]!=1000000000) high=a[i][j];
            if(a[i][j]<low) low=a[i][j];        
        } 
    while(low<=high)//二分查找 
    {
        int mid=(low+high)/2;
        if(check(mid)==1) high=mid-1;
        else low=mid+1;        
    }
    cout<<low<<endl;   
    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