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

麻烦大家帮我找一找错误,一直wa,我检查了很久都没有结果,先谢谢了!!!

Posted by sunnyboy1001 at 2008-04-29 16:30:47 on Problem 2767
#include<stdio.h>
double ans;
void f(int a[10][4],int b[10],double c[10],int n);
int main(void)
{
   int num,zu,a[10][4]={0},n,i,b[10]={0};
   double c[10]={0};
   scanf("%d",&num);
   for(zu=1;zu<=num;zu++){
      b[0]=0;
      ans=-1;
      scanf("%d",&n);
      for(i=0;i<n;i++)
         scanf("%d%d%d",&a[i][1],&a[i][2],&a[i][3]);
      f(a,b,c,n);
      printf("%d\n",(int)ans);
   }   
   system("pause");
   return 0;
}    
void f(int a[10][4],int b[10],double c[10],int n)
{
   int i,k,j,flag=0;
   double h1,h2,maxh,hh;
   int d[10]={0};
   double e[10]={0};
   for(j=0;j<n;j++){
      if(a[j][0]==0){
         flag=1; 
         a[j][0]=1;
         if(b[0]==0){
            d[0]=1;
            d[1]=j;
            e[1]=0;
            f(a,d,e,n);
         }   
         else{
            maxh=c[b[0]];
            for(k=1;k<=b[0];k++){
               i=b[k];
               hh=c[k];
               if((a[i][3]-a[i][2])*a[j][1]>=(a[j][3]-a[j][2])*a[i][1]){
                  if(a[j][2]>=a[i][3]&&hh+a[i][1]>maxh)
                     maxh=hh+a[i][1];
                  if(a[j][2]>a[i][2]&&a[j][2]<a[i][3]){
                     h2=hh+(a[j][2]-a[i][2])*a[i][1]/(a[i][3]-a[i][2]);
                     if(h2>maxh)
                         maxh=h2;
                  }   
               }
               else{
                  if(a[j][2]>=a[i][3]){
                     if(hh+a[i][1]>maxh)
                        maxh=hh+a[i][1];
                  }   
                  else if(a[j][3]<=a[i][3]){
                     h1=(a[j][3]-a[i][2])*a[i][1]/(a[i][3]-a[i][2]);
                     if(h1>a[j][1]){
                        h2=h1-a[j][1]+hh;
                        if(h2>maxh)
                           maxh=h2;
                     }   
                  }   
                  else{
                     h1=(a[i][3]-a[j][2])*a[j][1]/(a[j][3]-a[j][2]);
                     if(h1<a[i][1]){
                        h2=hh+a[i][1]-h1;
                        if(h2>maxh)
                           maxh=h2;
                     }   
                  }   
               }      
            }   
            for(k=1;k<=b[0]&&c[k]+a[b[k]][1]>maxh+a[j][1];k++);
            d[0]=k;
            for(k=1;k<d[0];k++){
               d[k]=b[k];
               e[k]=c[k];
            }   
            d[k]=j;
            e[k]=maxh;
            /*i=b[0];
            b[0]=k;
            k=b[b[0]];
            b[b[0]]=j;
            hh=c[b[0]];
            c[b[0]]=maxh;*/
            f(a,d,e,n);
            /*c[b[0]]=hh;
            b[b[0]]=k;
            b[0]=i;*/
         }   
         a[j][0]=0;
      }   
   }   
   if(flag==0){
      if(c[1]+a[b[1]][1]<ans||ans<0)
         ans=c[1]+a[b[1]][1];
   }   
}   

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