P1432
这个题是一个很简单的等比数列。
题目大意是:初始第一步 $ n_1 = 2 $,之后的每一步都比前一步减少 98%,即满足等比数列 $ 2 + 2 \times 0.98 + 2 \times 0.98^2 + \cdots \leq K $ ,K 为某个上限值。
利用 $ K = S_n = \frac{2 (1 - 0.98)^n}{1 - 0.98} \Rightarrow n = log_{0.98} (1 - \frac{K}{100}) $
貌似 math.h/cmath 中的log没有能指定任意底数的,但注意到 $ log_a b = \frac{log_c b}{log_c a} $,所以也能计算。
代码:
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define min(a, b) ((a) < (b) ? (a) : (b))
int gcd(int a, int b){return b == 0 ? a : gcd(a%b, a);}
const int N = 1500000;
int main()
{
double dis; int n;
scanf("%lf", &dis);
n = (int)ceil(log(1 - dis/100.)/log(0.98));
return printf("%d\n", n), 0;
}
P1432的更多相关文章
- 洛谷P1432 倒水问题(CODEVS.1226)
To 洛谷.1432 倒水问题 题目背景 In the movie "Die Hard 3", Bruce Willis and Samuel L. Jackson were co ...
- 洛谷P1432 倒水问题
题目背景 In the movie "Die Hard 3", Bruce Willis and Samuel L. Jackson were confronted with th ...
- 洛谷 P1432 倒水问题
目录 题目 思路 \(Code\) 题目 戳 思路 \(bfs\) 第一遍提交\(50\),第二遍就\(100\)了,qwq \(Code\) #include<iostream> #in ...
- entity framework core 支持批量插入,值得期待
entity framework6.x之前搞了这么多版本,构架这么牛B,居然没有批量插入更新的功能,但有很多替换的解决方案,例如Entity Framework Extended Library(ht ...
随机推荐
- 一次列表页伪静态的实现;结合nginx rewrite
nginx伪静态: rewrite ^/(.*)-htm-(.*)$ /$1.php?$2; 将 list-html-t-3-p-4.html 转到list.php?t-3-p-4 t-3-p-4 用 ...
- 图像滤波—opencv函数
函数原型 方框滤波 ,-), bool normalize = true, int borderType = BORDER_DEFAULT) 均值滤波 ,-), int borderType = ...
- C++-POJ2503-Babelfish[hash]
哈个希加挂个链表 一个要背的字符串hash函数ELFhash() mod数取数据最大容量的1.5倍最佳?! #include <set> #include <map> #inc ...
- Git 从远端指定分支克隆代码到本地
不指定分支默认是master git clone + clone 地址 # 例如 git clone https://amc-msra.visualstudio.com/xxx/_xx/xxxxxx ...
- 题解【洛谷P1407】 [国家集训队]稳定婚姻
题面 题解 很好的\(Tarjan\)练习题. 主要讲一下如何建图. 先用\(STL \ map\)把每个人的名字映射成数字. 输入第\(i\)对夫妻时把女性映射成\(i\),把男性映射成\(i+n\ ...
- Reading Comprehensive
我是红色 When I re-entered the full-time workforce a few years ago after a decade of solitary[隐士,独居] sel ...
- 每天进步一点点------Allegro中SYMBOL种类
Allegro 中SYMBOL 种类在Allegro 中, Symbol 有五种, 它们分别是Package Symbol .Mechanical Symbol.Format Symbol.Shape ...
- 隐藏wordpress版本信息
在主题中的functions.php中添加如下代码: remove_action( 'wp_head', 'wp_generator');
- SpringBoot集成mybatis以及自动化测试代码实现
Mybatis和logback的应用配置 1.在module的pom.xml文件中,加载springboot和swagger.lombok.fastjson.mysql.mybatis包 2.在res ...
- C#堆和栈的入门理解
声明:以下内容从网络整理,非原创,适当待入个人理解. 解释1.栈是编译期间就分配好的内存空间,因此你的代码中必须就栈的大小有明确的定义:堆是程序运行期间动态分配的内存空间,你可以根据程序的运行情况确定 ...