Uriel's Corner

Research Associate @ Harvard University / Research Interests: Computer Vision, Biomedical Image Analysis, Machine Learning
posts - 0, comments - 50, trackbacks - 0, articles - 594

POJ 1676 What time is it?---模拟

Posted on 2009-10-06 21:55 Uriel 阅读(444) 评论(0)  编辑 收藏 引用 所属分类: POJ模拟

暑假以来一直没做过模拟。。急剧退化。。搞了数小时。。WA到死啊。。。
没什么trick,没什么好说的。。。纯模拟。。。
改来改去,改来改去。。代码不是一般的恶心啊。。。

/*Problem: 1676  User: Uriel 
   Memory: 180K  Time: 0MS 
   Language: C++  Result: Accepted
*/
 

#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>

int stnd[10][3][3]={{{0,1,0},{2,0,2},{2,1,2}},{{0,0,0},{0,0,2},{0,0,2}},{{0,1,0},{0,1,2},{2,1,0}},
                    
{{0,1,0},{0,1,2},{0,1,2}},{{0,0,0},{2,1,2},{0,0,2}},{{0,1,0},{2,1,0},{0,1,2}},
                    
{{0,1,0},{2,1,0},{2,1,2}},{{0,1,0},{0,0,2},{0,0,2}},{{0,1,0},{2,1,2},{2,1,2}},
                    
{{0,1,0},{2,1,2},{0,1,2}}}
;
int i,j,k,m,cse,g,h,n,res,temp,y,nn; 
int minute,hour,crt[4];
int sum[2][4];//每个时间每一位有几种表示 
int x[2];//每个时间有几种可能表示 
int flag[5][5][12];//保存每一位的每一格,1为_,2为|,0为空 
int num[10][5][5];//每一位每种可能的具体值 
int Time[5][10010];//每个时间每种的可能值,化为分钟 
char t[5][5][20];//输入                                   
                    
int main()
{
    scanf(
"%d",&cse);
    
while(1)
    
{
N:      
if(!cse)break;
        cse
--;
        memset(t,
0x00,sizeof(t));
        
for(i=0;i<3;i++)
        
{
            getchar();
            
for(j=0;j<12;j++)
            
{               
                scanf(
"%c",&t[0][i][j]);
            }

//            t[0][i][12]='\0';
//            printf("*%s*\n",t[0][i]);
            getchar();
//            getchar();
            for(j=0;j<12;j++)
            
{
                scanf(
"%c",&t[1][i][j]);
            }

//            printf("*%s*\n",t[1][i]);
        }

/*        for(i=0;i<3;i++)
        {
            printf("%s",t[0][i]);
            printf("%s",t[1][i]);
            printf("\n");
        }                   
*/
    
                
//        getchar();
//        getchar();
//        for(i=0;i<26;i++)getchar();
//        getline();
        for(i=0;i<3;i++)//每个case显示一共3行 
        {
            
for(j=0;j<12;j++)
            
{
                
if(t[0][i][j]=='_')
                
{
                    flag[
0][i][j]=1;
                }

                
else if(t[0][i][j]=='|')
                
{
                    flag[
0][i][j]=2;
                }

                
else
                
{
                    flag[
0][i][j]=0;
                }

                
if(t[1][i][j]=='_')
                
{
                    flag[
1][i][j]=1;
                }

                
else if(t[1][i][j]=='|')
                
{
                    flag[
1][i][j]=2;
                }

                
else
                
{
                    flag[
1][i][j]=0;
                }

            }

        }

/*        for(i=0;i<3;i++)//每个case显示一共3行 
        {
            for(j=0;j<12;j++)
            {
                printf("%d ",flag[0][i][j]);
            }
            for(j=0;j<12;j++)
            {
                printf("%d ",flag[1][i][j]);
            }
            printf("\n");
        }                   
*/

        
for(i=0;i<2;i++)//pre and after
        {
            
for(j=0;j<4;j++)//sum of digits
            {
                sum[i][j]
=0;
                
for(h=0;h<10;h++)
                
{
                    
if(j==0 && h>2)break;
                    
if(j==2 && h>5)break;
                    y
=0;
                    
for(k=0;k<3;k++)
                    
{
                        
for(g=0;g<3;g++)
                        
{                            
                            
if(flag[i][k][g+3*j]!=stnd[h][k][g] && flag[i][k][g+3*j])
                            
{
                                y
=1;
                                
goto M;
                            }

                        }

                    }

M:                  
if(!y)
                    
{
//                        printf("*");
                        sum[i][j]++;
                        num[sum[i][j]
-1][i][j]=h;
//                        if(j==1 && i==1)printf("*h=%d*",h);
                    }

                }

                
if(!sum[i][j])
                
{
                    printf(
"Not Sure\n");
                    
goto N;
                }

//                if(sum!=1)
//                {
//                    printf("Not Sure\n");
//                    goto M;
//                }
            }

        }

        
        
for(i=0;i<2;i++)
        
{
            x[i]
=0
            
for(j=0;j<sum[i][0];j++)
            
{
                
for(k=0;k<sum[i][1];k++)
                
{
                    
for(h=0;h<sum[i][2];h++)
                    
{
                        
for(m=0;m<sum[i][3];m++)
                        
{                           
                            Time[i][x[i]
++]=(num[j][i][0]*10+num[k][i][1])*60+num[h][i][2]*10+num[m][i][3];
                        }

                    }

                }

            }

        }

        res
=0;
        
for(i=0;i<x[0];i++)
        
{
            
for(j=0;j<x[1];j++)
            
{
//                printf("*%d %d*\n",Time[0][i],Time[1][j]);
                if(Time[0][i]<1440 && Time[1][j]<1440 && (Time[0][i]-Time[1][j]==15 || Time[1][j]-Time[0][i]==1425))
                
{
//                    printf("xx%d:%d %d:%d\n",Time[0][i]/60,Time[0][i]%60,Time[1][j]/60,Time[1][j]%60);
                    res++;
                    temp
=i;
//                    nn=j;
                }

            }

        }

//        printf("*%d*\n",res);
//        printf("*%d %d*\n",Time[0][temp],Time[1][nn]);
        if(res==1)
        
{
            minute
=Time[0][temp]%60;
            hour
=Time[0][temp]/60;
            crt[
0]=hour/10;
            crt[
1]=hour%10;
            crt[
2]=minute/10;
            crt[
3]=minute%10;
            printf(
"%d%d%d%d\n",crt[0],crt[1],crt[2],crt[3]);
        }

        
else
        
{
            printf(
"Not Sure\n");
        }
                                                   
    }

//    system("PAUSE");
    return 0;
}
                      
        

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理