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. 从零搭建ES搜索服务(一)基本概念及环境搭建

    一.前言 本系列文章最终目标是为了快速搭建一个简易可用的搜索服务.方案并不一定是最优,但实现难度较低. 二.背景 近期公司在重构老系统,需求是要求知识库支持全文检索. 我们知道普通的数据库 like ...

  2. 不要再用if(xxx != null)或者try catch NullPointerException了,Optional可以帮你解决

    public static void testIfPresent() { Map<String, Map<String, String>> map = new HashMap& ...

  3. Playmaker全面实践教程之简单的使用Playmaker示例

    Playmaker全面实践教程之简单的使用Playmaker示例 简单的使用Playmaker示例 通过本章前面部分的学习,相信读者已经对Playmaker有了一个整体的认识和印象了.在本章的最后,我 ...

  4. BZOJ.4766.文艺计算姬(Prufer)

    题目链接 这是完全二分图,那么在构造Prufer序列时,最后会剩下两个点,两点的边是连接两个集合的,这两个点自然分属两个集合 那么集合A被删了m-1次,每次从n个点中选:B被删了n-1次,每次都可以从 ...

  5. 11.1 正睿停课训练 Day14

    目录 2018.11.1 正睿停课训练 Day14 A 字符串 B 取数游戏(贪心) C 魔方(模拟) 考试代码 B C 2018.11.1 正睿停课训练 Day14 时间:3.5h 期望得分:100 ...

  6. BZOJ4888 [Tjoi2017]异或和 FFT或树状数组+二进制拆位

    题面 戳这里 简要题解 做法一 因为所有数的和才100w,所以我们可以直接求出所有区间和. 直接把前缀和存到一个权值数组,再倒着存一遍,大力卷积一波. 这样做在bzoj目前还过不了,但是luogu开O ...

  7. 树上统计treecnt(dsu on tree 并查集 正难则反)

    题目链接 dalao们怎么都写的线段树合并啊.. dsu跑的好慢. \(Description\) 给定一棵\(n(n\leq 10^5)\)个点的树. 定义\(Tree[L,R]\)表示为了使得\( ...

  8. window + php + memcached 安装

    第一步:安装windows版memcached 下载地址:http://download.csdn.net/detail/zhaotengfei36520/8182503#comment 下载之后将文 ...

  9. GOCN每日新闻(2017-08-12)

    1.为什么我们从 Python 转向 Go 2.Go 实现常见数据结构 3.3年半,50万行 Go 代码 4.Go 游戏引擎 oka 5.Go 是隐藏学习曲线的语言

  10. 【转】Intellij IDEA调试功能

    http://www.cnblogs.com/winner-0715/p/5422952.html 先编译好要调试的程序.1.设置断点