Hdu1393_weird Clock "Water Problem"

Source: Internet
Author: User

Weird Clock

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)Total Submission (s): 2636 Accepted Submission (s): 943
Problem Description
A weird clock marked from 0 to have only a minute hand. It won ' t move until a special coin is thrown to its box. There is different kinds of coins as your options. However once you do your choice, you cannot use any other kind. There is infinite number of coins of each kind, each marked with a number D (1 <= d <=), meaning-this C Oin'll make the minute hand move D times clockwise the current time. For example, if the current time is, and d = 2. Then the minute hand would move clockwise minutes and would be pointing to 15.

Now is given the initial time S (1 <= s <=) and the coin ' s type D. Write a program to find the minimum num ber of D-coins needed to turn the minute hand back to 0.

Input
There is several tests. Each test occupies a line containing the positive integers s and d.

The input is finished to a line containing 0 0.

Output
For each test, print in a, 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

Author

DU, Peng


The main topic: there is a table, the top of a total of 0~59, each scale represents a minute,

Give you the current minute s, and a number d,d indicates that you can turn the D time clockwise for a minute. That

Can turn d*s minutes at a time, ask: Can the table go to 0 top. If you can go to 0, the output meets the

Ask the minimum number of times; otherwise output "Impossible".

Ideas: Very wonderful topic requirements, according to the requirements of the solution can, every time remember to 6 to take the remainder, because

The dial is looped in 60.


#include <stdio.h> #include <string.h>int main () {    int s,d;    while (~SCANF ("%d%d", &s,&d) && (s| | d))    {        if (s >=)            s%=;        int count = 0,flag = 1;        while (s)        {            S + = s*d;            s%=;            if (Count > +)            {                flag = 0;                break;            }            count++;        }        if (flag)            printf ("%d\n", count);        else            printf ("impossible\n");    }    return 0;}



Hdu1393_weird Clock "Water Problem"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.