你打我啊

Time Limit: 500ms   Memory limit: 65536K  有疑问?点这里^_^

题目描述

最近看了一个非常好玩的题,如果有972杯水,其中有971个没有毒的,1个有毒的, 其中有毒的水的毒性需要一周才会发作,那么,我们最少需要多少只小白鼠才能够在一周的时间内确定那一杯水是有毒的。当然这种水题肯定难不住各位队员们。所 以我要出的题和上述的东西没有一点关系。
 
那既然上面的东西和这次的题没有什么关系那我为什么要说呢,很明显,我在凑字数,我实在是不知道该怎么凑了呀,他们说让我来一个又臭又长一看就不想做的题,还让我用英文写,所以嘛,我英语不好只能先来个中文废话了,Ok上正题吧。
 
Christmas was coming .Mr Smith had no money to buy any presents for his children .His wife was ill and he spent a lot of money on her medicine .
And the harvest was bad and all his family were going go be 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 to walk on the road covered with thick snow .
Two hours later he was very tied and wanted to have a rest .He put the box to the ground and sat down .
“The air in the box must be 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 you are !”Mr Smith called out angrily .“You can herald the break of day at night but you cann’t find the way to the town in the daytime !”
 
Ok,It is a nonsense.Our question is what I mentioned in the first paragraph,if we have N cups of water.How many mice we need.

输入

 多组输入,每组输入一个N(1<=N<=2^32-1);

输出

 输出小白鼠的数目

示例输入

1000
972

示例输出

10
10 算法分析:其实这道题和《找假硬币》一样的道理。
这有n杯水,让老鼠A品尝n/2,剩余的n/2 由B来喝!
如果老鼠A死了,说明有毒的水在A这边,否则在B那边,就按照这种思路一直把确定好的有毒水那一边的所有水半分给两只老鼠
喝,这样做最后绝对会确定出哪一杯水有毒!
#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 周赛 找有毒的那杯水(思维逻辑 + 分治思想 )的更多相关文章

  1. SDUT OJ 1221 亲和数 (找出某个数n所有的因子数,只需要暴力:2->sqrt(n) 即可 )

    亲和数 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 如果a的因子和等于b,b的因子和等于a,且a≠b,则称a,b为亲和数对. ...

  2. SDUT OJ 2607

    /*http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2607*/ 题目大意:给出一个字符串,求出里 ...

  3. SDUT OJ 图练习-BFS-从起点到目标点的最短步数 (vector二维数组模拟邻接表+bfs , *【模板】 )

    图练习-BFS-从起点到目标点的最短步数 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 在古老的魔兽传说中,有两个军团,一个叫天 ...

  4. 九度OJ 1035:找出直系亲属(二叉树)

    题目1035:找出直系亲属 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1309 解决:521 题目描述: 如果A,B是C的父母亲,则A,B是C的parent,C是A,B的child,如 ...

  5. 【小米oj】找出单独的数字

    题目链接:https://code.mi.com/problem/list/view?id=2&cid=0&sid=26251#codearea 描述 给出N个数字.其中仅有一个数字出 ...

  6. SDUT OJ 数据结构实验之图论八:欧拉回路

    数据结构实验之图论八:欧拉回路 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...

  7. SDUT OJ 学密码学一定得学程序

    学密码学一定得学程序 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Description ...

  8. SDUT OJ 数据结构实验之串一:KMP简单应用 && 浅谈对看毛片算法的理解

    数据结构实验之串一:KMP简单应用 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descr ...

  9. 【离散数学】 SDUT OJ 传递闭包 && memset 使用注意事项

    传递闭包 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description 已知有n头牛,m次战斗关系, ...

随机推荐

  1. concurrentHashMap面试题

    面试题: ConcurrentHashMap有哪些构造函数? ConcurrentHashMap使用什么技术来保证线程安全? ConcurrentHashMap的get方法是否要加锁,为什么? Con ...

  2. LightOJ1106 Gone Fishing

    Gone Fishing John is going on a fishing trip. He has h hours available, and there are n lakes in the ...

  3. laravel控制器

    //访问MemberController下的info的方法 //方法一//访问路径http://localhost/Laravel/public/member/infoRoute::get('memb ...

  4. luogu P1704 寻找最优美做题曲线

    题目背景 nodgd是一个喜欢写程序的同学,前不久(好像还是有点久了)洛谷OJ横空出世,nodgd同学当然第一时间来到洛谷OJ刷题.于是发生了一系列有趣的事情,他就打算用这些事情来出题恶心大家-- 题 ...

  5. 【Java TCP/IP Socket】应用程序协议中消息的成帧与解析(含代码)

    程序间达成的某种包含了信息交换的形式和意义的共识称为协议,用来实现特定应用程序的协议叫做应用程序协议.大部分应用程序协议是根据由字段序列组成的离散信息定义的,其中每个字段中都包含了一段以位序列编码(即 ...

  6. open-falcon的插件机制

    Plugin可以看做是对agent功能的扩充.对于业务系统的监控指标采集,最好不要做成plugin,而是把采集脚本放到业务程序发布包中,随着业务代码上线而上线,随着业务代码升级而升级,这样会比较容易管 ...

  7. ImportError: No module named _curses;Color support is disabled, python-curses is not installed.解决办法

    linux系统默认安装了python2.6, 但是发现python2.7 import curses时 提示 找不到_curses 错误.  用pip(python2.7 )安装了curses-204 ...

  8. [cocos2d-x]怎样降低cocos2d-x游戏的耗电量?

    Cocos2d-x游戏的耗电量一直是个让人头疼的问题,一个简单的三消游戏,玩一会手机就热得发烫,更郁闷的是电池消耗非常快.基本上两个小时就能够把电池耗光. 近期又看到一个帖子.有个老外用cocos2d ...

  9. 手机加载优化 - 2x、3x图

    人们常说,现在的流量不值钱了,图越大越好咯! 我想说的是,浏览器虽然不值钱了,但速度还是略快吧! 文章来自:UI妹儿 icon_alipay.png→iPhone 1-3代的手机(已经不考虑了) ic ...

  10. 关于Java中强制类型转换的问题

    为了更好的理解我们先看下面的例子: package com.yonyou.test; import java.util.ArrayList; import java.util.Iterator; im ...