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<cstdio> #include<iostream> #include<string> using namespace std; #define infinity 1000 int n; int **g;//存储权值 char **s;//输入字符串 int *lowcost; int *closeset; bool *used; int Prime(int **g,int n){ int minlen=0; lowcost=new int[n]; closeset=new int[n]; used=new bool[n]; int i,j,k; for(i=0;i<n;i++){ lowcost[i]=g[0][i]; closeset[i]=0; used[i]=0; } used[0]=1; for(i=1;i<n;i++){ j=0; while(used[j])j++; for(k=0;k<n;k++){ if(!used[k]&&lowcost[k]<lowcost[j]) j=k; } used[j]=1; minlen+=lowcost[j]; for(k=0;k<n;k++){ if(!used[k]&&g[j][k]<lowcost[k]){ lowcost[k]=g[j][k]; closeset[k]=j; } } } return minlen; delete lowcost,closeset,used; } int main(){ int i,j,k; while(cin>>n&&n!=0){ s=new char*[n]; g=new int*[n]; for(i=0;i<n;i++)s[i]=new char[7]; for(i=0;i<n;i++)g[i]=new int[n]; for(i=0;i<n;i++)cin>>s[i]; for(i=0;i<n;i++){ for(j=0;j<n;j++){ if(i!=j) g[i][j]=infinity; else g[i][j]=0; } } for(i=0;i<n;i++){ int temp; for(j=i+1;j<n;j++){ temp=0; for(k=0;k<7;k++){ if(s[i][k]!=s[j][k])temp++; } g[i][j]=temp; } } cout<<"The highest possible quality is 1/"<<Prime(g,n)<<"."<<endl; } for(i=0;i<n;i++)delete g[i]; for(i=0;i<n;i++)delete s[i]; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator