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 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;
                }
            }
        }

    }

}
时间: 2025-01-16 15:21:47

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

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 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 k

杭电 HDU ACM 1393 Weird Clock

Weird Clock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2752    Accepted Submission(s): 990 Problem Description A weird clock marked from 0 to 59 has only a minute hand. It won't move until

HDOJ 1163 Eddy&#39;s digital Roots(简单数论)

[思路]:http://blog.csdn.net/iamskying/article/details/4738838 求解思路: 现在分析一个问题,假设将十位数为a,个位数为b的一个整数表示为ab,则推导得 ab*ab = (a*10+b)*(a*10+b) = 100*a*a+10*2*a*b+b*b 根据上式可得:root(ab*ab) = a*a+2*a*b+b*b = (a+b)*(a+b);[公式一] 同理也可证得:root(ab*ab*ab) = (a+b)*(a+b)*(a+b)

hdoj 5387(Clock)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5387 比较水的一道题目,也是自己单翘的第一道题目吧,题意就是找到给定时间时钟三个指针之间的夹角, 需要注意的问题分数的表示方法,辗转相除求最大公因子,同时除去, 此外还应注意夹角为锐角. 1 #include<stdio.h> 2 #include<cmath> 3 #include<algorithm> 4 using namespace std; 5 int gcd(i

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

Problem Description A有1数m,B来猜.B每猜一次,A就说"太大","太小"或"对了" . 问B猜n次可以猜到的最大数. Input 第1行是整数T,表示有T组数据,下面有T行 每行一个整数n (1 ≤ n ≤ 30) Output 猜n次可以猜到的最大数 Sample Input 2 1 3 Sample Output 1 7 这个题目我总感觉题意没说明白,没办法.参考了一下网上的题意. 题意就是: 最多猜n次一定可以猜到1

【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^k的所有因式.思路就是按照上面的方式,先找到k的约束的多项式,然后求得最后一个因式的系数.求得所有[2,1001]的因式后.对因式进行重新排序,并按照格式输出.输出时注意系数为1,阶数为0,阶数为1. 1 /* 3205 */ 2 #include <iostream> 3 #include &l

RMQ问题 - ST表的简单应用

2017-08-26 22:25:57 writer:pprp 题意很简单,给你一串数字,问你给定区间中最大值减去给定区间中的最小值是多少? 用ST表即可实现 一开始无脑套模板,找了最大值,找了最小值,分别用两个函数实现,实际上十分冗余 所以TLE了 之后改成一个函数中同时处理最大值和最小值,就可以了 AC代码如下: /* @theme:poj 3264 @writer:pprp @declare:ST表(sparse table)稀疏表,用动态规划的思想来解决RMQ问题: @date:2017

POJ 3094 Quicksum(简单题)

[题意简述]:题意很简单.看例子就能理解 [分析]:略.字符串的读取操作. // 200K 0Ms #include<iostream> using namespace std; int main() { char a[256]; while(1) { int sum = 0; gets(a); if(strcmp(a,"#")==0) break; int len = strlen(a); for(int i = 0;i<len;i++) { if(a[i] ==

HDU3123:GCC(同余模简单题)

题目:http://acm.hdu.edu.cn/showproblem.php?pid=3123 题意很简单,就是同余模的简单应用. 代码如下: #include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> typedef __int64 ll; using namespace std; char a[10010]; int n,m; ll zan,sum;