题意:有n个药瓶,里面有一个有毒,然后每次拿兔子去试吃k瓶并且只能是k瓶,如果兔子死了就知道那瓶是毒药了,现在问你最少兔子要试吃几次。

分析:这题卡了好久,其实很简单。先考虑肯定要吃n/k次,那么剩下的如果只有一瓶或没有,则答案就是n/k,如果有两瓶以上,则只需再吃一次就行了。因为兔子只需在剩下的m瓶里吃m-1瓶,然后在之前的n-m瓶中吃(k-m+1)瓶,就可以知道剩下的那个是毒药了。

 #include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
using namespace std;
typedef long long ll;
int main()
{
ll n,k;
scanf("%I64d%I64d",&n,&k);
ll ans=n/k,r=n%k;
if(n==k&&n!=) printf("-1\n");
else{
if(k==) printf("%d\n",n-);
else{
if(r==||r==) printf("%I64d\n",ans);
else printf("%I64d\n",ans+);
}
}
return ;
}

Gym 100187A-Potion of Immortality的更多相关文章

  1. CF Gym 100187A Potion of Immortality (思路,最坏情况的最小损失)

    根据兔子试药情况可以缩小范围,如果死了,不在试过的药里面,如果活着,在试过的药里. 最糟的情况: 两个原则 1.能确定魔药所在的范围的尽量大,2.死得兔子尽量多. 如果当前不知道情况的药n为k的二倍以 ...

  2. codeforces Gym 100187A A. Potion of Immortality

    A. Potion of Immortality Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1001 ...

  3. Gym - 100187A A - Potion of Immortality —— 贪心

    题目链接:http://codeforces.com/gym/100187/problem/A 题解: 光题意就想了很久:在最坏情况下的最小兔子数.其实就是至少用几只兔子就一定能找出仙药(答案存在的话 ...

  4. codeforces Gym 100500H A. Potion of Immortality 简单DP

    Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...

  5. Gym 101981I - Magic Potion - [最大流][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem I]

    题目链接:http://codeforces.com/gym/101981/attachments There are n heroes and m monsters living in an isl ...

  6. codeforces gym #101161H - Witcher Potion(状压DP)

    题目链接: http://codeforces.com/gym/101161/attachments 题意: 总共有n瓶药可供选择 每瓶药可以增加$e_i$点体力,和$p_i$点毒性 每分钟消耗1点毒 ...

  7. Gym - 101981I The 2018 ICPC Asia Nanjing Regional Contest I.Magic Potion 最大流

    题面 题意:n个英雄,m个怪兽,第i个英雄可以打第i个集合里的一个怪兽,一个怪兽可以在多个集合里,有k瓶药水,每个英雄最多喝一次,可以多打一只怪兽,求最多打多少只 n,m,k<=500 题解:显 ...

  8. Magic Potion(最大流,跑两遍网络流或者加一个中转点)

    Magic Potion http://codeforces.com/gym/101981/attachments/download/7891/20182019-acmicpc-asia-nanjin ...

  9. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

随机推荐

  1. Gdi+实用入门

    大部分是参照其它资料,然后加以自己的理解,那是什么,总结.算不得什么教程.......汗,自己看着就行了..如果别人能看那就更好了. 首先下载GDI+文件包,一个动态链接库,使用GDI+就是调用那个动 ...

  2. JAVA 抛出与声明异常

    在编程过程中,我们往往会遇到这种情况,在当前环境中无法解决,比如用户传入的参数错误,IO设备问题等.此时,就要从当前环境中抛出异常提交给上级来处理. 在JAVA语言中,使用throw关键字来抛出异常. ...

  3. Android MediaPlayer播放一般音频与SoundPool播放短促的音效

    [1]使用MediaPlayer实现一般的音频播放 MediaPlayer播放通常的音频文件 MediaPlayer mediaPlayer = new MediaPlayer(); if (medi ...

  4. Rewriting History with Git Rebase

    http://code.tutsplus.com/tutorials/rewriting-history-with-git-rebase--cms-23191 1. Rebasing for a Li ...

  5. King(差分约束)

    http://poj.org/problem?id=1364 题意真心看不大懂啊... 现在假设有一个这样的序列,S={a1,a2,a3,a4...ai...at}其中ai=a*si,其实这句可以忽略 ...

  6. 1057 - Collecting Gold (状态压缩DP)

    题目大意: 给你一个矩阵,'x'是你的起始位置, 'g'是宝藏的位置,问最少多少步可以把所有的宝藏取完,并且最后返回起始位置. 注意:没有宝藏的时候输出 0   =================== ...

  7. PowerDesigner 怎么给 Table Properties 增加注释和默认值

    1.  选中表,右键 2. 选中“comment”, 这个就是列的注释 3.还是这个页面 ,往下有个“default value”, 这个就是你设置的默认值. 4. 这个是怎么设置默认值.

  8. use isSubstring to check if one word is a rotation of another.

      1: /// <summary> 2: /// Assume you have a method isSubstring which checks if one word is a s ...

  9. ubuntu12.04下使用qemu模拟mips处理器安装debian

    注:ubuntu是不支持mips处理器的,只能在x86下安装运行第一步.安装qemu sudo apt-get install qemu qemu-system .执行 qemu-system-mip ...

  10. ffmpeg, libav学习记录

    转载自:http://hi.baidu.com/y11022053/item/81f12035182257332e0f8196 一个偶然遇到了ffmpeg,看起来不多,而且通用性很强,算是一个扎实的技 ...