Sdut OJ to find the poisonous glass of water (thinking logic + binary thought)

Source: Internet
Author: User

You hit me. Time limit:500ms Memory limit:65536k have questions? Dot here ^_^ Topic description recently saw a very interesting question, if there are 972 cups of water, of which 971 are not poisonous, 1 poisonous, toxic water toxicity of which will take a week to attack, then, we need at least how many mice to be able to determine in a week the glass of water is poisonous. Of course, this water problem must be difficult for members of the team. So I'm going to have a problem that doesn't have anything to do with the above.   Since the above is not related to this question why do I have to say, it is clear that I am in the number of words, I really do not know how to make up ah, they say let me to a smelly and long look do not want to do, also let me write in English, so, my English is not good can only first to a Chinese nonsense, OK, let's go to the chase.  christmas was coming. Mr Smith had no money to buy any presents for his children. His wife is ill and he spent a lot of money in her medicine. And the harvest is bad and all his family were going go is hungry the next spring. He was quite worried about it. " We had only a cock, "said Mrs Smith one day." You ' d better take it to the town. Sell it there and buy some cakes and sweets for our children. "" It ' s a good idea! " The man said and caught the cock the next morning and put it into a box. It was difficult-walk on the road covered with thick snow. The hours later he is very tied and wanted to a rest. He put the box to the ground and sat down. The air in the box must is close, "the man said to himself." I ' d better let the COck walk outside for a while, or it ' ll die. So he put the cock to the ground. When he started again, he couldn ' t catch it any longer. " How Foolish is! " Mr Smith called out angrily. " You can herald the break's at night if you Cann ' t find the the-the-the-town in the daytime! "  ok,it is a nonsense. Our question are what I mentioned in the first paragraph,if we have N cups of water. How many mice we need. Input  multiple sets of inputs, one N (1<=n<=2^32-1) per group;Outputnumber of output miceSample input
Sample output
1010

#include <iostream>  #include <string>  #include <stdio.h>  #include <algorithm>    using namespace std;    int MAX (int a, int b)  {      return a>b?a:b;  }    int main ()  {      unsigned int n;      unsigned int cnt;      while (scanf ("%d", &n)!=eof)      {          cnt=0;          while (n!=0)          {              n=n/2;              cnt++;          }          cout<<cnt<<endl;      }      return 0;  }  

Sdut OJ to find the poisonous glass of water (thinking logic + binary thought)

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.