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 |
帮我看看怎么处理TLE,代码如下#include <iostream> #include <cmath> using namespace std; #define MAX 10 double RST[MAX]; //×îºóÓÃÀ´¼Ç¼ÿλbitsÊÇ1µÄ¸ÅÂÊ bool MAIT[1024][1024]; // ÁÚ½Ó¾ØÕ󣬱íʾnodeµÄÁ´½ÓÇé¿ö int FIR[1024]; // n¸öÊý¸÷Óм¸¸ö±ß£¨²»Öظ´£© double dp[101][1024]; //¼Ç¼ÿһ²½£¬²úÉú0--1023µÄ¸ÅÂÊ int k,n,e; void init() { memset(RST,0.0,sizeof(RST) ); memset(MAIT, false, sizeof(MAIT) ); memset(FIR, 0, sizeof(FIR) ); memset (dp, 0.0 , sizeof(dp)); } void make(int i) //ÅжÏÿһ²½²úÉúµÄÊý×Ö¶ÔnµÄ¸ÅÂÊ { int ii=0; int tmp; int num = pow(2,n); for(int j=0;j<num;j++){ //¸öÊý ii=0; tmp=j; while(true){ if(tmp%2 != 0) RST[ii]= RST[ii]+ dp[i][j]; tmp = tmp>>1; ii++; if(tmp==0) break; } } } void doit() //½ÚµãÊýÁ¿pow(2,n),±àºÅ0,1,2,3,....,pow(2,n)-1; { int i = 0; int num = pow(2,n); while( i< num ){ dp[1][i] = 1.0/(double)num; i++; } int kk=2; int j; while(kk<=k){ for(i=0; i< num ;i++){ for(j=0;j<num;j++){ if( MAIT[i][j] ) dp[kk][i] = dp[kk][i] + dp[kk-1][j] / (double)FIR[j]; } } memset(RST,0.0,sizeof(RST) ); make(kk); for(i=0;i<n;i++){ if( RST[i] >= 0.75 || RST[i]<=0.25){ printf("No\n"); return; } } kk++; } printf("Yes\n"); } int main() { scanf("%d%d%d", &k,&n,&e); int ee; int v1,v2; while(k!=0) { init(); ee=0; while(ee< e) { scanf("%d%d", &v1,&v2); if(!MAIT[v1][v2]){ FIR[v1]++; FIR[v2]++; } MAIT[v1][v2] = true; MAIT[v2][v1] =true; ee++; } doit(); scanf("%d%d%d", &k,&n,&e); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator