Gym 100187A-Potion of Immortality
题意:有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的更多相关文章
- CF Gym 100187A Potion of Immortality (思路,最坏情况的最小损失)
根据兔子试药情况可以缩小范围,如果死了,不在试过的药里面,如果活着,在试过的药里. 最糟的情况: 两个原则 1.能确定魔药所在的范围的尽量大,2.死得兔子尽量多. 如果当前不知道情况的药n为k的二倍以 ...
- codeforces Gym 100187A A. Potion of Immortality
A. Potion of Immortality Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1001 ...
- Gym - 100187A A - Potion of Immortality —— 贪心
题目链接:http://codeforces.com/gym/100187/problem/A 题解: 光题意就想了很久:在最坏情况下的最小兔子数.其实就是至少用几只兔子就一定能找出仙药(答案存在的话 ...
- 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 ...
- 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 ...
- codeforces gym #101161H - Witcher Potion(状压DP)
题目链接: http://codeforces.com/gym/101161/attachments 题意: 总共有n瓶药可供选择 每瓶药可以增加$e_i$点体力,和$p_i$点毒性 每分钟消耗1点毒 ...
- Gym - 101981I The 2018 ICPC Asia Nanjing Regional Contest I.Magic Potion 最大流
题面 题意:n个英雄,m个怪兽,第i个英雄可以打第i个集合里的一个怪兽,一个怪兽可以在多个集合里,有k瓶药水,每个英雄最多喝一次,可以多打一只怪兽,求最多打多少只 n,m,k<=500 题解:显 ...
- Magic Potion(最大流,跑两遍网络流或者加一个中转点)
Magic Potion http://codeforces.com/gym/101981/attachments/download/7891/20182019-acmicpc-asia-nanjin ...
- 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 ...
随机推荐
- 【HDOJ】1695 GCD
莫比乌斯反演简单题目. /* 1695 */ #include <iostream> #include <string> #include <map> #inclu ...
- Learning WCF Chapter2 WCF Contracts and Serialization
So far I’ve talked about the standards behind it all,but in fact WCF hides most of this from the dev ...
- dom4j中 selectSingleNode 或selectNodes获取不到节点的原因总结 (转)
没想到搞个dom4j会出这么多怪错.. 最近在研究XBRL GL的有关内容,在项目中要求吧XBRL GL导入到11179注册库中,根据11179建立数据库,然后从XBRL GL分类标准中导入数据到数据 ...
- bzoj1295
考虑到这道题n,m都很小,我们考虑先穷举起点i 下面我们要做的是找出移走k个障碍后,点i所能到的最大距离 我们可以把这个问题转化为判定性问题 对于一对点i,j,如果他们之间存在一条路径,障碍数(包括起 ...
- 如何修复在Microsoft Azure中“虚拟机防火墙打开,关闭RDP的连接端口”问题
注:下列步骤并不一定适用所有场景,提供思路,请灵活应用 我们在使用Microsoft Azure 中Windows 虚拟机,有时会发生错误打开防火墙或一些管家软件错误的关闭了"远程桌面 ...
- js前台与后台数据交互-后台调前台(后台调用、注册客户端脚本)
转自:http://blog.csdn.net/wang379275614/article/details/17049721 客户端脚本一般都在前台,这里讲的是(1)在后台调用前台定义的脚本(2)在后 ...
- atomic_t原子操作
所谓原子操作,就是该操作绝不会在执行完毕前被任何其他任务或事件打断,也就说,它的最小的执行单位,不可能有比它更小的执行单位,因此这里的原子实际是使用了物理学里的物质微粒的概念. 原子操作需要硬件的支持 ...
- C语言练习题_邮票组合
背景: 我们寄信都要贴邮票,在邮局有一些小面值的邮票,通过这些小面值邮票中的一张或几张的组合,可以满足不同邮件的不同的邮资. 现在,邮局有4种不同面值的邮票.在每个信封上最 ...
- openstack libtray
OpenStack packages¶ Distributions release OpenStack packages as part of the distribution or using ot ...
- select * from table where 1=1让您茅塞顿开(转)
在很多网站上,都经常看到select * from table where 1=1这样的一种查询语句: 这是一种怎样的查询语句呢?首先说明,1=1不是查询语句中的任何关键词,所以,请您放心,不管你会不 ...