ZOJ 1476 题解

代码
 1 #include<iostream>
 2 #include<map>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7 map<int , int> m;
 8 int s ;
 9 int d;
10 int res ;
11 int t ;
12 
13 while(1)
14 {
15    scanf("%d%d",&s,&d);
16    if(s == 0 && d == 0)
17     break;
18    res = 0 ;
19    while(1)
20    {
21     if(s == 0)
22     {
23      printf("%d\n",res) ;
24      break ;
25     }
26    
27     m[s] = 1;
28     t = d * s ;
29     s += t ;
30     s = s % 60;
31     if(m[s])
32     {
33      printf("Impossible\n");
34      break;
35     }
36     m[s] = 1 ;res ++;
37    }
38    m.clear();
39 }
40 
41 }


    题目链接:http://acm.zju.edu.cn/show_problem.php?pid=1476

    按照ac数排序,这道居然以前没发现,现在反正在找简单题,这题应该也够简单吧。

    题目的意思,就是一个钟,它只有分针,而且是可以投币的,投币的作用就是让这个分针转,投入的币是有种类的,比如投入的是2,就是转动当前时间的2倍时 间,现在给出当前时间和投入的币,要求得到最少多少个这样的币可以使分针归零。

    当然,看到这样的题目肯定是直接模拟了,因为分的时间最多也只有60,每次转动如果以前出现过了就代表不可能归零了,如果已经归零的,当然成功了。

    于是代码如下:in C++


posted on 2010-02-05 01:52  vivy  阅读(237)  评论(0编辑  收藏  举报