HUNAN UNIVERSITY ACM/ICPC Judge Online_Problem 11146_Number Guessing

Number Guessing
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB
Total submit users: 43, Accepted users: 35
Problem 11146 : No special judgement
Problem description
Number Guessing is a computer game. First, the computer chooses four different digits, you need to guess these four digits in the fewest times,for each guess, the computer will show a judgement in the form of "#A#B", "#" is a number 0~4. "#A" shows how many digits you guessed with both correct value and position. "#B" shows how many digits you guessed with correct value. For example, the computer chose 1234, and you guessed 6139, the computer will show "1A2B" for you have number "1" correct value but wrong position and number "3" correct value with correct position.Thus the computer gives you the judgement of "1A2B"

Now you have memorized the digits you guessed and the judgements you got, you feel like you can figure out the correct answer. Life is filled with wisdom, isn't it?

Input
There are several test cases. For each test case, the first line contains a single positive integer N indicates the times you can guess,the following N lines is the record of the guess, in the form:

#### #A#B

The first four numbers is the numbers guessed, then the judgements for your guess.

The input terminated when N is not postive integer, and not need to proceed.

Output
For each test case, output a single line contains exactly four digits that the computer has chosen. You may assume that each test case gives you enough information, so you can figure out the correct answer.
Sample Input
2
1234 2A4B
1243 0A4B
3
0732 3A3B
1526 0A0B
4567 0A2B
-1
Sample Output
2134
0734
Problem Source
Dr Wu

CODE

/*

  Name: 11146_Number Guessing

  Copyright:  yangchun's

  Author:  yangchun

  Date: 26-05-08 09:36

  Description:  HUNAN UNIVERSITY ACM/ICPC Judge Online_Problem 11146_Number Guessing

*/



#include <algorithm>

#include <iostream>



#define Loop(x) for(x=0;x<10;++x)

#define Loop1(x,y) for(x=0;x<y;++x)



using namespace std;



int num=0,_result[5041]={0};

char result[5041][5]={'/0'};



int main()

{

    int i1,i2,i3,i4,i=1,j,_j,k,_k;

 	//freopen("in.txt","r",stdin);

    //freopen("out.txt","w",stdout);

    

    Loop(i1)                    //初始化result[5040][5]数组 

    {

        result[i][0] = i1+'0';

        Loop(i2)

        {

             if(i2!=i1)    result[i][1] = i2+'0';

             else continue;             

             Loop(i3)

             {

                 if(i3!=i1 && i3!=i2)     result[i][2] = i3+'0';

                 else continue;                

                 Loop(i4)

                 {

                     if(i4!=i1 && i4!=i2 && i4!=i3)

                     {

                          result[i][3] = i4+'0';                           

                          //printf("%s/t%d/n",result[i],num+1); 

                          i++,num++;   

                          strcpy(result[i],result[i-1]);

                     }     

                     else continue;               

                 }//for(i4=...)

             }//for(i3=...)               

        }//for(i2=...)           

    }//for(i1=...)

    

    int N,num_a,num_b;

    char guess[5],guess_result[5];

    while(scanf("%d",&N),N>0)

    {

        memset(_result,0,sizeof(_result));                     

       //读入第一组数据,并找出符合要求的排列组合,

       //把他们的数组序号记录在_result[5041]数组中.... 

       scanf("%s%s",guess,guess_result);

       Loop1(j,5040)

       {

            num_a = num_b = 0;

                         

            for(k=0;k<4;k++)

            {

                if(result[j][k] == guess[k])

                   num_a ++;                         

            }

            

            if(num_a == guess_result[0]-'0')

            {

                for(i1=0;i1<4;i1++)

                   for(i2=0;i2<4;i2++)

                       if(result[j][i2] == guess[i1]) 

                             num_b++;

                if(num_b == guess_result[2]-'0')

                {

                     _result[0]++;

                     _result[_result[0]] = j;    

                }                              

            }             

       }//Loop1(j,5040)

       

         

       //步步优化结果集,把不符合新读入数据的结果去掉,缩小范围

       //即:动态规划 

           

       Loop1(j,N-1) 

       {

           scanf("%s%s",guess,guess_result);                          

           int temp=0; 

           for(k=1;k<=_result[0];k++)

           {

                num_a = num_b = 0;                    

                            

                for(_k=0;_k<4;_k++)

                {

                    if(result[_result[k]][_k] == guess[_k])

                       num_a ++;                         

                }

                

                if(num_a == guess_result[0]-'0')

                {

                    for(i1=0;i1<4;i1++)

                       for(i2=0;i2<4;i2++)

                           if(result[_result[k]][i2] == guess[i1]) 

                                 num_b++;

                    if(num_b == guess_result[2]-'0')

                    {

                        temp++;

                        _result[temp] = _result[k];

                    }                                                       

                }                          

           }               

           _result[0] = temp;

       }//Loop1(j,N-1)

                  

       printf("%s/n",result[_result[1]]);                       

    }

    return 0;

} 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值