Problem Description

A weird clock marked from 0 to 59 has only a minute hand. It won’t move until a special coin is thrown into its box. There are different kinds of coins as your options. However once you make your choice, you cannot use any other kind. There are infinite number of coins of each kind, each marked with a number d ( 1 <= d <= 1000 ), meaning that this coin will make the minute hand move d times clockwise the current time. For example, if the current time is 45, and d = 2. Then the minute hand will move clockwise 90 minutes and will be pointing to 15.

Now you are given the initial time s ( 1 <= s <= 59 ) and the coin’s type d. Write a program to find the minimum number of d-coins needed to turn the minute hand back to 0.

Input

There are several tests. Each test occupies a line containing two positive integers s and d.

The input is finished by a line containing 0 0.

Output

For each test print in a single line the minimum number of coins needed. If it is impossible to turn the hand back to 0, output “Impossible”.

Sample Input

30 1

0 0

Sample Output

1

明确题意之后就简单了,

思路:一个钟面仅仅有一根分针。对于一个数字d,把钟面上的分针指向的时间s往后拨s的d倍。问给定d,反复这种操作多少次能回拨到0。

若不能则输出Impossible。

注意:此处的s是不断更新的。!!。!

。!!!!!

由于钟面仅仅有60分钟。所以最多不会超过60次,直接暴力就可。


import java.util.Scanner; public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); while(sc.hasNext()){
int s= sc.nextInt();
int d = sc.nextInt();
if(s==0&&d==0){
return ;
}
int num=s;
for(int i=1;i<65;i++){
num = (num+(num*d))%60;
if(num==0){
System.out.println(i);
break;
}
if(i>63){
System.out.println("Impossible");
break;
}
}
} } }

HDOJ 1393 Weird Clock(明确题意就简单了)的更多相关文章

  1. HDOJ 1393 Weird Clock(明白题意就简单了)

    Problem Description A weird clock marked from 0 to 59 has only a minute hand. It won't move until a ...

  2. HDU 1393 Weird Clock (英语,纪念题)

    这题简单,只要看懂题目就好,坑爹的是我的英语水平太差了,wa了n次,所以 仅此纪念 一下. //坑爹的英语题目,注意重点:move d times clockwise the current time ...

  3. hdoj 5387(Clock)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5387 比较水的一道题目,也是自己单翘的第一道题目吧,题意就是找到给定时间时钟三个指针之间的夹角, 需要 ...

  4. HDOJ(HDU) 2178 猜数字(题意有点难理解、、、)

    Problem Description A有1数m,B来猜.B每猜一次,A就说"太大","太小"或"对了" . 问B猜n次可以猜到的最大数. ...

  5. HDOJ 1196 Lowest Bit(二进制相关的简单题)

    Problem Description Given an positive integer A (1 <= A <= 100), output the lowest bit of A. F ...

  6. HDU——1393Weird Clock(水题,注意题意)

    Weird Clock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  7. 【HDOJ】3205 Factorization

    题意很简单.就是求x^k-1的因式分解.显然x-1必然是其中之一(x=1, x^k-1=0).假设k=mp. 则x^k = (x^p)^m, 同理x^p-1必然是其中之一,即x^p的所有因式一定是x^ ...

  8. 人体时钟hone hone clock

    摘要:一个由日本人设计的有意思的Flash时钟:人体时钟 hone hone clock .安装很简单,直接js导入即可,包括两种样式:透明背景和白色背景. 很可爱的一个设计,实现后效果如下: 使用方 ...

  9. HDU4523+简单

    题意很简单. 一次最多多切出一条边! 其余的就没什么好说的了 import java.util.*; import java.math.*; public class Main{ public sta ...

随机推荐

  1. Python常用模块--string

    该模块提供3个常用的功能: * 提供常用的字符串常量(感觉用途不大) * 提供字符串替换功能,主要用途是上下文的国际化(通过str可以实现,不介绍,感兴趣的自己看官网) * 提供字符串的格式化功能(感 ...

  2. gbdt xgboost 贼难理解!

    https://www.zybuluo.com/yxd/note/611571 https://zhuanlan.zhihu.com/p/29765582 gbdt 在看统计学习方法的时候 理解很吃力 ...

  3. spark加载模型与gRPC与JSF与JDQ冲突

    spark与JSF冲突解决方式 <dependency> <groupId>org.apache.spark</groupId> <artifactId> ...

  4. BZOJ.3262.陌上花开([模板]CDQ分治 三维偏序)

    题目链接 BZOJ3262 洛谷P3810 /* 5904kb 872ms 对于相邻x,y,z相同的元素要进行去重,并记录次数算入贡献(它们之间产生的答案是一样的,但不去重会..) */ #inclu ...

  5. 洛谷.3254.圆桌问题(最大流ISAP)

    题目链接 日常水题 还是忍不住吐槽这题奇怪的评价 #include <cstdio> #include <cctype> #include <algorithm> ...

  6. PHP Math 函数 mt_rand() 使用 Mersenne Twister 算法返回随机整数。

    语法 mt_rand(min,max) 说明 如果没有提供可选参数 min 和 max,mt_rand() 返回 0 到 RAND_MAX 之间的伪随机数.例如想要 5 到 15(包括 5 和 15) ...

  7. java的关键字与保留字

    1,Java 关键字列表 (依字母排序 共50组): abstract, assert, boolean, break, byte, case, catch, char, class, const(保 ...

  8. 20172302 《Java软件结构与数据结构》第三周学习总结

    2018年学习总结博客总目录:第一周 第二周 第三周 教材学习内容总结 第五章 队列 1.队列是一种线性集合,其元素从一端加入,从另一端删除:队列元素是按先进先出(FIFO(First in Firs ...

  9. saltstack 命令2

    在Salt主机上,可以快速查看所有Salt minion连接,并查看连接是否被接受,拒绝或挂起 [root@node1 ~]# salt-key -L 接受所有的key [root@node1 ~]# ...

  10. UVa 127 - &quot;Accordian&quot; Patience POJ 1214 链表题解

    UVa和POJ都有这道题. 不同的是UVa要求区分单复数,而POJ不要求. 使用STL做会比較简单,这里纯粹使用指针做了,很麻烦的指针操作,一不小心就错. 调试起来还是很费力的 本题理解起来也是挺费力 ...