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 |
错在哪??牛人帮忙看看,谢谢/*用枚举的方法枚举每一种情况 *2006,3,25 *下午 *poj 1166 *-------------------------------------------*/ #include<iostream> #include<cmath> using namespace std; bool check(int array[]); int allusednum; int movestep[10][10]={{0,0,0,0,0,0,0,0,0,0}, {0,1,1,0,1,1,0,0,0,0},//1 {0,1,1,1,0,0,0,0,0,0},//2 {0,0,1,1,0,1,1,0,0,0},//3 {0,1,0,0,1,0,0,1,0,0},//4 {0,0,1,0,1,1,1,0,1,0},//5 {0,0,0,1,0,0,1,0,0,1},//6 {0,0,0,0,1,1,0,1,1,0},//7 {0,0,0,0,0,0,0,1,1,1},//8 {0,0,0,0,0,1,1,0,1,1}};//9 int main() { int original_sense[10],usedtimes[10],temp[10],output[10]; long min=0; min=int(pow(4,9)); //give them number memset(original_sense,0,10*sizeof(int)); memset(usedtimes,0,10*sizeof(int)); memset(temp,0,10*sizeof( int )); memset(output,0,10*sizeof( int )); //input for(int j=1;j<=9;j++){ cin>>original_sense[j]; temp[j]=original_sense[j]; } //begin to count-find out the times of every move for( usedtimes[1]=0;usedtimes[1]<=3;usedtimes[1]++) for( usedtimes[2]=0;usedtimes[2]<=3;usedtimes[2]++) for( usedtimes[3]=0;usedtimes[3]<=3;usedtimes[3]++) for( usedtimes[4]=0;usedtimes[4]<=3;usedtimes[4]++) for( usedtimes[5]=0;usedtimes[5]<=3;usedtimes[5]++) for( usedtimes[6]=0;usedtimes[6]<=3;usedtimes[6]++) for( usedtimes[7]=0;usedtimes[7]<=3;usedtimes[7]++) for( usedtimes[8]=0;usedtimes[8]<=3;usedtimes[8]++) for( usedtimes[9]=0;usedtimes[9]<=3;usedtimes[9]++) { //相加所有步骤对闹钟的影响 for(int i=1;i<=9;i++) for(int j=1;j<=9;j++) temp[i]=temp[i]+usedtimes[j]*movestep[j][i]; // //求所有步骤的总数 for( i=1;i<=9;i++) allusednum+=usedtimes[i]; if(allusednum<min) { if(check(temp)) { min=allusednum; for(int i=1;i<=9;i++) output[i]=usedtimes[i]; allusednum=0; } } for(int k=1;k<=9;k++) temp[k]=original_sense[k]; } //输出 for(int i=1;i<=9;i++) for(int j=1;j<=output[i];j++) { cout<<i<<' '; } cout<<endl; return 0; } bool check(int array[]) { for(int i=1;i<=9;i++) if(array[i]%4!=0)return false; return true; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator