USACO 3.2 Spinning Wheels

USACO 3.2 Spinning Wheels

最多转360秒,各个轮子就复位了。所以在360秒内,每过一秒检测一下是否可以透过光即可。
用一个数组记录能透过0-359的轮子的个数,当在某一度轮子的个数达到了5,则说明光可以透过,输出即可。
否则说明是不可能有光透过。

#include  < iostream >
#include 
< fstream >

using   namespace  std;

ifstream in(
" spin.in " );
ofstream out(
" spin.out " );

struct  wedge{
    
int  start;
    
int  extent;
};

int  speed[ 5 ];
wedge wedges[
5 ][ 5 ];
int  wedge_num[ 5 ];

void  onesecond()
{
   
for ( int  i = 0 ;i < 5 ; ++ i){
       
for ( int  j = 0 ;j < wedge_num[i]; ++ j){
           wedges[i][j].start
+= speed[i];
           wedges[i][j].start
%= 360 ;
       }
   } 
}

bool  isok()
{
    
int  tmp[ 360 ];

    memset(tmp,
0 , sizeof (tmp));

    
for ( int  i = 0 ;i < 5 ; ++ i){
        
for ( int  j = 0 ;j < wedge_num[i]; ++ j){
            
for ( int  k = 0 ;k <= wedges[i][j].extent; ++ k)
                tmp[(wedges[i][j].start
+ k) % 360 ] ++ ;
        }
    }

    
for ( int  i = 0 ;i < 360 ; ++ i)
        
if (tmp[i] == 5 )
            
return   true ;

    
return   false ;
}

void  solve()
{
    
for ( int  i = 0 ;i < 5 ; ++ i){
        
in >> speed[i];
        
in >> wedge_num[i];
        
for ( int  j = 0 ;j < wedge_num[i]; ++ j){
            
in >> wedges[i][j].start >> wedges[i][j].extent;
        }
    }

    
if (isok()){
        
out << 0 << endl;
        
return ;
    }

    
for ( int  i = 1 ;i <= 360 ; ++ i){
        onesecond();
        
if (isok()){
            
out << i << endl;
            
return ;
        }
    }
    
out << " none " << endl;
}

int  main( int  argc, char   * argv[])
{
    solve(); 
    
return   0 ;
}

你可能感兴趣的:(USACO 3.2 Spinning Wheels)