Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
怎么搞都超时啊,牛哥帮帮忙#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator