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 |
prim妥妥的#include <cstdio> #include <cstring> #include <map> #include <cmath> #include <queue> #include <string> #include <stack> #include <cstdlib> #include <iostream> #include <algorithm> #define abs(x) ((x)>0?(x):-(x)) #define __max(a,b) ((a)>(b)?(a):(b)) #define __min(a,b) ((a)<(b)?(a):(b)) #define rep(i,repstt,repend) for(int i=repstt;i<repend;i++) #define erep(i,repstt,repend) for(int i=repstt;i<=repend;i++) #define inf 0x7f//2147483647 #define iinf 0xffffff #define PI acos(-1.0) #define NOBUG puts("No_Bug_Hear"); #define STOP system("pause"); #define FOUT freopen("out.txt","w",stdout); #define FIN freopen("in.txt","r",stdin); #define OUTCLOSE fclose(stdout); #define INCLOSE fclose(stdin); #define INIT(a,b) memset(a,b,sizeof(a)) typedef long long ll; using namespace std; char f[2020][8]; int dis[2020],n; bool vst[2020]; int __d(char *ca,char *cb){ int cnt=0; rep(i,0,7) if(ca[i]!=cb[i]) cnt++; return cnt; } int prim(){ int tot=0; INIT(vst,0); rep(i,0,n)dis[i]=iinf; dis[0]=0; rep(i,0,n){ int tmin=iinf,k; rep(j,0,n) if(!vst[j]&&dis[j]<tmin){ tmin=dis[j]; k=j; } vst[k]=1; //if(tmin==iinf) return -1; tot+=tmin; rep(j,0,n) if(!vst[j]) dis[j]=__min(dis[j],__d(f[k],f[j])); } return tot; } int main(){ //FIN //FOUT while(scanf("%d",&n)&&n){ getchar(); rep(i,0,n)gets(f[i]); printf("The highest possible quality is 1/%d.\n",prim()); } //INCLOSE //OUTCLOSE return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator