Zoj 1476 Weird Clock (Tangled water problem)

Source: Internet
Author: User

Meaning


There is a strange clock only minutes of the pointer, a start to stop at the S branch, and then now have D-type coins, put into the clock will be d*s step, asked to need a few such coins.


Analysis:


The topic is not difficult, read understand should know is the use of the mark, because it is not difficult, I started without looking at the topic on the brush to write well, submitted WA, look at the topic to find is to ask a few coins can make the pointer back to 0. Then it was a tragedy to use a 1~1000 loop (which is the range of D >_<) so it's a tangled one.

Because the journey is the same, so when a certain point is repeated after the impossible to come out.

#include <stdio.h>
#include <string.h>
int main ()
{
	int s,d,i,sum;// This is limited to the scope of d rather than the scope of NUM, the title of the second interpretation of the wrong, not because the topic is simple and not carefully read the question.
	int flag[60];//The correct procedure is to mark each seat if it appears a second time, then repeat it, it is impossible to achieve 0 while
	(scanf ("%d%d", &s,&d)!=eof)
	{
		sum= s;
		i=0;
		if (s==0&&d==0) break;
		memset (flag,0,sizeof (flag));
		while (1)
		{
			s= (s+s*d)%60;
			i++;
			flag[s]++;
			if (s==0) break;
			if (flag[s]==2) break;
		if (s==0) printf ("%d\n", I);
		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.