你打我啊

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. “a++” 与 “++a” 的区别

    很久不写 C++ 程序,今天测试一段代码的过程中,发现自己连最基础的 C++ 知识都忘了,汗!!! a++ 与 ++a 都是表达式,他们都有值.其中: 1)a++ 的值是 a 的原始值,这个表达式的功 ...

  2. cf299C Weird Game

    Weird Game Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, ...

  3. robotframework安装和配置【转IBM:https://www.ibm.com/developerworks/cn/opensource/os-cn-robot-framework/index.html】

    内容   概览 Robot Framework 介绍 Robot Framework 的安装和配置 RIDE 编辑器介绍 创建测试项目 简单的测试用例的编写 总结 相关主题 评论   Robot Fr ...

  4. uva 10140 素数筛选(两次)

    #include<iostream> #include<cstring> #include<cmath> #include<cstdio> using ...

  5. SHoj A序列

    A序列 发布时间: 2017年7月9日 18:17   最后更新: 2017年7月9日 21:05   时间限制: 1000ms   内存限制: 128M 描述 如果一个序列有奇数个正整数组成,不妨令 ...

  6. Python入门---易错已错易混淆----知识点

    1.not 1 or 0 and 1 or 3 and 4 or 5 and 6 or 7 and 8 and 9 结果会输出啥? 根据优先级:(not 1) or (0 and 1) or (3 a ...

  7. Scrapy学习-9-FromRequest

    用FromRequest模拟登陆知乎网站 实例 默认登陆成功以后的请求都会带上cookie # -*- coding: utf-8 -*- import re import json import d ...

  8. CODEVS_1033 蚯蚓的游戏问题 网络流 最小费用流 拆点

    原题链接:http://codevs.cn/problem/1033/ 题目描述 Description 在一块梯形田地上,一群蚯蚓在做收集食物游戏.蚯蚓们把梯形田地上的食物堆积整理如下: a(1,1 ...

  9. Spring实战Day7面向切面编程术语介绍

    #### 面向切面编程 为什么需要切面? 有些功能需要在应用中的多个地方使用到,但是我们又不想在着每个地方都调用他们 切面术语 通知(advice):切面需要完成的工作 通知的类型(什么时间完成工作) ...

  10. linux命令stat,查看文件详细信息

    可以查看文件的各类具体信息:文件权限的数字形式0664:uid.gid的权限的数字形式等 更多用法参考stat --help lsattr test.sh 查看文件的其他属性:只读属性.只可以追加写属 ...