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 qyhelen at 2008-08-23 21:07:33 on Problem 2421
#include <iostream>
using namespace std;
int a[4951],b[4951],value[4951],f[4951];
void qsort(int value[],int m,int n)
{
     int p=m,q=n,mid=value[(m+n)/2];
     do
     {
         while(value[p]<mid && p<n)
         p++;
         while(value[q]>mid && q>m)
         q--;
         if(p<=q)
         {
                 swap(value[p],value[q]);
                 swap(a[p],a[q]);
                 swap(b[p],b[q]);
                 swap(f[p],f[q]);
                 p++;
                 q--;
         }
     }while(p<=q);
     if(q>m)
     qsort(value,m,q);
     if(p<n)
     qsort(value,p,n);
}
int main()
{
    int n;
    cin>>n;
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    memset(f,0,sizeof(f));
    memset(value,0,sizeof(value));
    int temp,flag=0,i,j;
    for(i=1;i<=n;i++)
    for(j=1;j<=n;j++)
    {
                     cin>>temp;
                     if(temp!=0 && i<j)
                     {
                                a[flag]=i;
                                b[flag]=j;
                                value[flag]=temp;
                                f[flag]=flag;
                                flag++;
                     }
    }
    int q,temp1;
    cin>>q;
    for(i=0;i<q;i++)
    {
                    cin>>temp>>temp1;
                    for(j=0;j<=n-1;j++)
                    if((a[j]==temp && b[j]==temp1) || (b[j]==temp && a[j]==temp1))
                    value[j]=0;
    }
    qsort(value,0,flag-1);
    int sum=0,k=0,m1=0,m2=0,sn1=0,sn2=0;
    j=0;
    while(k<flag-1)
    {
                   m1=a[j];
                   m2=b[j];
                   sn1=f[m1];
                   sn2=f[m2];
                   if(sn1!=sn2)
                   {
                               sum+=value[j];
                               k++;
                               for(i=0;i<flag;i++)
                               if(f[i]==sn2)
                               f[i]=sn1;
                   }
                   j++;
    }
    cout<<sum;
    system("pause");
    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