Poj Solution 2815

http://poj.org/problem?id=2815

#include <stdio.h>
#include <memory.h>
#include <string.h>
#include <math.h>

double get_angle( double s, double f, double m ) {

    if( s >= 12 )
        s -= 12;
    s = ( s+f/60+m/7200 ) / 12 * 360;
    f = ( f+m/120 )/60 * 360;
    f -= s;
    if( f < 0 )
        f += 360;
    return f;
}
double ans[24][60][120];
int main( ) {
    int i, j, k, a, ii, jj, kk;
    double t;
    for( i=0; i<24; i++ )
    for( j=0; j<60; j++ )
    for( k=0; k<120; k++ ) 
        ans[i][j][k] = get_angle( i, j, k );
//    printf( "%lf %lf %lfn", ans[9][16][21*2], ans[9][16][21*2+1], ans[9][16][22*2] );
    while( 1 ) {
        scanf( "%d %d:%d:%d", &a, &i, &j, &k );
        t = ans[i][j][k*2];        
        if( a < 0 )
            break;            
        if( fabs( t - a ) < 1e-7 ) {
            printf( "%02d:%02d:%02dn", i, j, k );
            continue;
        }
        ii = i, jj = j, kk = k;
        for(  ; ; i=(i+1)%24 )
        for( j%=60; j<60; j++ )
        for( k%=60; k<60; k++ )
        if( k != kk )
        {
            if( ans[i][j][2*k] - t > 0 ) {
                if(    ans[i][j][k*2]-a > 0 && 0 <= a-t )
                        goto over;
            }
            else if( a-t >= 0 || 0 < ans[i][j][2*k]-a )
                goto over;
            t = ans[i][j][2*k];
            ii=i, jj=j, kk=k;
//            printf( "%lfn", t );
        }        
over:
        printf( "%02d:%02d:%02dn", ii, jj, kk );
    }
    return 0;
}
        
            
            
        
    
											
This entry was posted in poj. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *