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

怎么搞都超时啊,牛哥帮帮忙

Posted by javvy at 2010-08-28 00:38:49 on Problem 1789
#include "iostream"
#include "string"
using namespace std;

char s[2000][8];
char vex[2000][8];
int used[2000];

int distance(char s1[],char s2[])
{
         int temp=0;          
         for(int i=0;i<strlen(s1);i++)
                 if(s1[i]!=s2[i])
                                temp++;
         return temp;                  
}

int main()
{
   int n;
   while(cin>>n)
   {               
          if(n==0)break;
          int rs=0;
          int top=0;         
          for(int i=0;i<n;i++)
          {       
                  scanf("%s",*(s+i));
                  used[i]=0;               
          }
          
          for(int i=0;i<9;i++)
          {
                  vex[top][i]=s[0][i];
          }
          top++;
          *used=1;
          
          while(1)
          {
                  int index=-1;
                  int dis=8;
                  for(int i=0;i<top;i++)
                  {
                          for(int j=0;j<n;j++)
                          {
                              int temp=distance(*(s+j),*(vex+i));   
                              if(!*(used+j)&&temp<dis)
                              {
                                    index=j;
                                    dis=temp;                                    
                              }
                          }        
                  }
                  if(index==-1)
                               break;
                  rs=rs+dis;
                  for(int i=0;i<9;i++)
                  {
                          vex[top][i]=s[index][i];
                  }
                  used[index]=1;
                  
          }
          
          cout<<"The highest possible quality is 1/"<<rs<<"."<<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