| ||||||||||
| 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 | |||||||||
1166-the clocks 谁来看看我的程序,一上午WA的天昏地暗#include<iostream>
using namespace std ;
int clock[10] , turn[10] ,re[10],max = 28 ;
int clockturn[10][6] = { {0},{1,2,4,0},{1,2,3,5,0},{2,3,6,0},{4,5,7,0},{1,3,5,7,9,0},{3,5,6,9,0},{4,7,8,0},{5,7,8,9,0},{6,8,9,0} };
int check ( )
{
int i , j , s ;
for ( i = 1 ; i <= 9 ;i ++ )
{
s = clock[i] ;
for ( j = 0 ; clockturn[i][j] ;j ++ )
{
s += turn[clockturn[i][j]] ;
s %= 4 ;
}
if ( s )
return 0 ;
}
return 1 ;
}
int sum ()
{
int s = 0 ;
for ( int i = 1 ; i < 10 ;i ++ )
s += turn[i] ;
return s ;
}
void search ( int t )
{
int i , tm ;
for ( i = 0 ; i < 4 ;i ++ )
{
turn[t] = i ;
if ( t == 9 )
{
if ( check ( ) )
{
tm = sum ();
if ( tm < max )
{
max = tm ;
memcpy ( re,turn,sizeof ( turn ) ) ;
}
return ;
}
}
else
search ( t+1 ) ;
}
}
int main ()
{
int i ,j ,first = 1 ;
for ( i = 1 ; i <= 9 ; i ++ )
cin >> clock[i] ;
memset ( turn ,0 ,sizeof ( turn ) ) ;
search (1) ;
for ( i = 1; i < 10 ; i ++ )
for ( j = 0 ; j < re[i] ; j ++ )
{
if ( first )
first = 0 ;
else
cout << ' ' ;
cout << i ;
}
cout << endl ;
return 0 ;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator