HDOJ1393 Weird Clock
来源:互联网 发布:什么叫网络投资 编辑:程序博客网 时间:2024/06/05 07:40
Weird Clock
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4200 Accepted Submission(s): 1564
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.
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.
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 10 0
Sample Output
1
需要读懂题意,一个时钟,只有分针,现在他正指向一个位置n,有一种硬币m,投入一次就可以使时钟顺时针转n*m分钟。
然后n的是变了(0--59)的,再继续投入这样的硬币,一直到n指向0,或者判断到他不肯指向0.
n是0--59的,每60次肯定是有一个循环的,所以暴力法解决就OK
import java.util.Scanner;public class Main{private static Scanner scanner;public static void main(String[] args) {scanner = new Scanner(System.in);while (scanner.hasNext()) {int n = scanner.nextInt();int m = scanner.nextInt();if (n == 0 && m == 0) {break;}boolean isZero = false;int i = 0;for (i = 1; i <= 60; i++) {n = (n + m*n) % 60;//System.out.println(n);if (n == 0) {isZero = true;break;}}if (isZero) {System.out.println(i);} else {System.out.println("Impossible");}}}}
阅读全文
0 0
- HDOJ1393 Weird Clock
- Weird Clock
- Weird Clock
- zoj 1476 Weird Clock
- HDU 1393 Weird Clock
- HDU1393:Weird Clock
- hdu1393 Weird Clock
- HOJ 1006 Weird clock
- HDU 1393 Weird Clock
- hdu 1393 Weird Clock
- HOJ 1006 Weird Clock
- hdu 1393 Weird Clock
- HDU 1393 Weird Clock
- 1393.Weird Clock
- HDU1393 Weird Clock
- HDOJ 1393 Weird Clock
- hdoj.1393 Weird Clock 20140825
- 杭电 HDU ACM 1393 Weird Clock
- Oracle 查询数据库有多少张表
- [转载]kaldi学习笔记:run.sh(egs/timit/s5)详细分析:从数据准备到特征提取
- 父子进程间通信---通过设置环境变量
- Eclipse 常用设置
- SQL truncate 、delete与drop区别
- HDOJ1393 Weird Clock
- 这七种迹象,暗示你的生活正慢慢变好
- 使用AntiSamy防范XSS跨站脚本攻击
- JACK_C#_游戏英雄武器和攻击
- SIM7600CE TCP success AT
- STM32——SPI接口
- redis使用场景
- zookeeper 介绍
- 无向图的深度优先搜索