[Blue Bridge Cup] [algorithm improves VIP] to find the three-digit

 

[Blue Bridge Cup] [algorithm improves VIP] to find the three-digit

Time limit: 1Sec Memory Limit: 128MB submitted: 4 Solution: 3

Title Description

The 1,2, ..., 9 9 number into three groups, each consisting of three three-digit number, and configured so that the three three-digit 
1: 2: 3 ratio, satisfy the conditions of the test to obtain all three three digits. 
For example: three three digits 192,384,576 satisfy the above conditions. 

Entry

No input file 

Export

The output of each row has three numbers, in order to meet the problem set three digits. Various actors of different solutions to meet the requirements. 

Sample input

no

Sample Output

no
 #include<iostream>
 #include<cstring>
 #include<algorithm>
 using namespace std;
 int  b[10],vis[10],ans;
 void dfs(int cur ){
 	  if( cur == 10 ){
 	  	  if( ( b[1]*100+b[2]*10 +b[3] ) * 2 == b[4]*100+b[5]*10+b[6] && ( b[1]*100+b[2]*10 +b[3] ) *3 == b[7]*100+b[8]*10+b[9] ){
               printf("%d %d %d\n",b[1]*100+b[2]*10 +b[3],b[4]*100+b[5]*10+b[6],b[7]*100+b[8]*10+b[9]) ; 	  	  	
		  }
		  return ;
	   }
      for( int i=1;i<=9;i++){
      	   if( !vis[i] ){
      	   	   vis[i] = 1;
      	   	   b[cur] = i;
      	   	   dfs(cur+1);
      	   	   vis[i] = 0;
			}
	  } 
 }
 
 int main(void){
    
 	 dfs(1 );
  
     return 0;
 }

 

Guess you like

Origin blog.csdn.net/S_999999/article/details/94600509