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. 通过反射的方式注入自己的ShutdownHook并清除其他HOOK

    String className = "java.lang.ApplicationShutdownHooks"; Class<?> clazz = Class.forN ...

  2. LOJ.116.[模板]有源汇有上下界最大流(Dinic)

    题目链接 http://blog.csdn.net/just_sort/article/details/75448403 有源汇有上下界网络流 通过添加一条(T->S,[0,INF])的边变成无 ...

  3. c/c++中int main(int argc,char *argv[])的具体含义

    int main(int argc,char * argv[ ]) argv为指针的指针 argc为整数 char **argv or: char *argv[ ] or: char argv[ ][ ...

  4. C++学习笔记43:STL

    STL简介(standard Template Library) STL的基本组件:容器(container),迭代器(iterator),函数对象(function object) 算法(algor ...

  5. Asp.Net Mvc 自定义扩展

    目录: 自定义模型IModelBinder 自定义模型验证 自定义视图引擎 自定义Html辅助方法 自定义Razor辅助方法 自定义Ajax辅助方法 自定义控制器扩展 自定义过滤器 自定义Action ...

  6. Oracle varchar与varchar2的区别

    varchar -- 存放定長的字符数据,最长2000個字符:varchar2 -- 存放可变长字符数据,最大长度为4000字符. varchar2是oracle提供的独特的数据类型oracle保证在 ...

  7. android:ViewHolder模式

    ViewHolder holder = null; if(convertView == null){ convertView = mInflater.inflate(R.layout.xxx null ...

  8. 使用Doxygen + graphviz生成Unity 3d的UGUI类图

    下载软件 1) Graphviz,下载地址:http://download.csdn.net/detail/u010953266/8591169 为什么不用官网?一是下载速度慢,二是下载到本地的文件貌 ...

  9. Amazon.com 美国亚马逊 直邮中国 手把手教程(转)

    什么值得买已经发布2014最新版美亚直邮攻略 海淘攻略:美国亚马逊 直邮服务 手把手教程(2014最新版) ,调整幅度较大,值友们可以移步到新攻略中查看. 相比德国.英国亚马逊,美国亚马逊的大部分商品 ...

  10. Facebook在代码里下毒,百度身受重伤。。。

    白首相知犹按剑     前两天看到有朋友分享说,WordPress停用了react.今天,在逛知乎时看到了另一个问题别细看这图,我赌你看不懂... 嗯...用人话来说就是百度内部要求他们的程序猿不要再 ...