Hang electric OJ question 1393 Weird clock problem report _ACM problem report

Source: Internet
Author: User
Weird Clock time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 1771 accepted submission (s): 643


Problem Description a weird clock marked from 0 to the has only a minute hand. It won ' t move until a special coin are thrown into its box. There are different kinds of coins as your options. However Once you do your choice, you cannot use the any other kind. There are infinite number of coins of each kind, all marked with a number D (1 <= d <= 1000), meaning so this C Oin'll make the minute hand the "D times clockwise the" times. For example, if it is, and d = 2. Then the minute hand'll move clockwise the minutes and would be pointing to 15.

Now, are 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 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
————————————————————————————————————————————————————————
Consider the failure to meet the requirements of the problem, that is, the output "impossible" condition is when the recurrence of the previous occurrence of the time is not able to meet the requirements, I set a length of 60 of the array record whether the current time has occurred.

/****************************
 *name:weird clock.c
 *tags:acm water
 *note: When the second occurrence of the same result is not possible to achieve the problem requirements, Output Impossible
 ****************************/

#include <stdio.h>

int main ()
{
      int s, D, T, SAVE[60], I;
      while (scanf ("%d%d", &s, &d)!= EOF && (S. | d)) {for
	    (i = 0; i <; i++) {
		  save[i] = 0;
	    }
	    if (d = = 0 && s) {
		  printf ("impossible\n");
		  Continue;
	    }
	    t = 0;
	    while (s!= 0 &&!save[s]) {
		  Save[s] = 1;
		  s = (S * (d + 1))%;
		  t++;
	    }
	    if (s = = 0) {
		  printf ("%d\n", t);
	    } else {
		  printf ("impossible\n");}
      }
      return 0;
}


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.