Gym - 100187A A - Potion of Immortality —— 贪心
题目链接:http://codeforces.com/gym/100187/problem/A
题解:
光题意就想了很久:在最坏情况下的最小兔子数。其实就是至少用几只兔子就一定能找出仙药(答案存在的话)。再注意一下特殊情况就可以了,
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <algorithm>
using namespace std;
#define pb push_back
#define mp make_pair
#define ms(a, b) memset((a), (b), sizeof(a))
//#define LOCAL
#define eps 0.0000001
typedef long long LL;
const int inf = 0x3f3f3f3f;
const int maxn = 200000+10;
const int mod = 1000000007; int main()
{
#ifdef LOCAL
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif // LOCAL
int n,k;
cin>>n>>k;
if(n==1) puts("0");
else if(n==k) puts("-1");
else if(k==1) printf("%d\n",n-1);
else
{
if(n%k==0||n%k==1)
printf("%d\n",n/k);
else
printf("%d\n",n/k+1);
}
}
Gym - 100187A A - Potion of Immortality —— 贪心的更多相关文章
- codeforces Gym 100187A A. Potion of Immortality
A. Potion of Immortality Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1001 ...
- 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 ...
- CF Gym 100187A Potion of Immortality (思路,最坏情况的最小损失)
根据兔子试药情况可以缩小范围,如果死了,不在试过的药里面,如果活着,在试过的药里. 最糟的情况: 两个原则 1.能确定魔药所在的范围的尽量大,2.死得兔子尽量多. 如果当前不知道情况的药n为k的二倍以 ...
- Codeforces Gym 100231B Intervals 线段树+二分+贪心
Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...
- codeforces Gym 100187F F - Doomsday 区间覆盖贪心
F. Doomsday Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/F ...
- 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 H. Hell on the Markets 贪心
Problem H. Hell on the MarketsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vj ...
- GYM 101755 K.Video Reviews 【贪心】+【二分】
<题目链接> 题目大意: 一家公司想让n个人给他们的产品评论,所以依次去找这n个人,第i个人会评论当且仅当已经有ai个人评论或他确实对这个产品感兴趣,但是这n个人都不对这个产品感兴趣,问这 ...
- GYM 101173 F.Free Figurines(贪心||并查集)
原题链接 题意:俄罗斯套娃,给出一个初始状态和终止状态,问至少需要多少步操作才能实现状态转化 贪心做法如果完全拆掉再重装,答案是p[i]和q[i]中不为0的值的个数.现在要求寻找最小步数,显然要减去一 ...
随机推荐
- 矩阵乘法加速fib数列
考虑矩阵(1,1)(1,0) #include<cstdio> #include<cstring> #include<iostream> using namespa ...
- 将压缩包文件(rar/zip)伪装成图片(jpg/gif/png/ico)
1.在Windows上使用copy命令,缺点是只能是jpg文件,gif不支持,命令如下: copy in1.jpg+in2.rar out.jpg 2.网上说使用UEdit方式可以制作gif,但是测试 ...
- xcode创建一个工程的多个taget,便于测试和发布多个版本
背景:很多时候,我们需要在一个工程中创立多个target,也就是说我们希望同一份代码可以创建两个应用,放到模拟器或者真机上,或者是,我们平时有N多人合作开发,当测试的时候,在A这里装了一遍测A写的那块 ...
- Android动画中Interpolator 详解和演示
遇到一个项目需求,想让动画变得更活泼一点,于是想到了动画属性中的Interpolator,写了基本例子测试一下Android提供给我们现成的加速器的效果: 效果 代码中方法 xml中属性 越来越快 A ...
- 将可执行程序的内存空间扩展到3GB(windows)
为了告知操作系统这个应用程序可以支持/3GB方式,我们需要往exe 文件头中添加一个 IMAGE_FILE_LARGE_ADDRESS_AWARE 标志.添加的方式很简单: 在你的系统的 Progra ...
- HDU3572Task Schedule(最大流 ISAP比較快)建图方法不错
Task Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- xgboost的SparkWithDataFrame版本实现
再xgboost的源码中有xgboost的SparkWithDataFrame的实现,如下:https://github.com/dmlc/xgboost/tree/master/jvm-packag ...
- sql导入数据库
有问题可以尝试加上这句 DROP TABLE IF EXISTS `t_saler_login_log`;
- js增加收藏
<html> <span style="white-space:pre"> </span><head> <span style ...
- 辛星深入分析vim的自己主动补全功能以及vim的映射
曾经对于vim的自己主动补全功能,都是须要的时候从网上下载点配置项,然后复制到自己的vimrc上去,自己也不知道是什么意思.结果发现搜索到的非常多自己主动补全的方式都非常另类,有的喜欢在补全大括号的时 ...