Wolf Chasing rabbits

Source: Internet
Author: User

Wolf Chasing rabbits
A rabbit hid in a 10-ring distribution of the hole in one of the wolf in the first hole did not find the rabbit, on the other hole, to the third hole to find, also did not find, on the two holes, to the sixth hole to find, after each one more hole to find rabbits ... This way, if you have not found the rabbit, may I ask the rabbit in which hole?

The order of the wolves looking for holes: first: 1; second: 3; third 6; fourth time: 10; fifth time: 5 ...

Clever conversion of the problem:
In which hole is the rabbit safe? "---equivalent---" What hole will wolves go for?
The wolf can not find the rabbit, then the infinite time to go on.
The 21st time the Wolf returned to the 1th hole, after that is repeated, the infinite is due to 21 times is enough.

#include <stdio.h>void main () {bool hole[11]={0};//10 hole int Pos=1;  for (int i=1;i<21;i++)//21st time The Wolf returned to the 1th hole {hole[pos]=true;        The wolf has looked for the hole pos+=i+1;      pos=pos%10; } for (int i=1;i<10;i++) if (!hole[i]) printf ("Rabbit may be in the hole in section%d \ n", i);}

The answer is: 2, 4, 7, 9 The safest, the wolf can not find

Wolf Chasing rabbits

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.