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 ...
随机推荐
- 在多租户(容器)数据库中如何创建PDB:方法5 DBCA远程克隆PDB
基于版本:19c (12.2.0.3) AskScuti 创建方法:DBCA静默远程克隆PDB.将 CDB1 中的 PDB1 克隆为 CDB2 中的 ERP2 对应路径:Creating a PDB ...
- HTTP慢速攻击
漏洞原理 HTTP慢速攻击也叫slow http attack,是一种DoS攻击的方式.由于HTTP请求底层使用TCP网络连接进行会话,因此如果中间件对会话超时时间设置不合理,并且HTTP在发送请求的 ...
- codeforces 1269E K Integers (二分+树状数组)
链接:https://codeforces.com/contest/1269/problem/E 题意:给一个序列P1,P2,P3,P4....Pi,每次可以交换两个相邻的元素,执行最小次数的交换移动 ...
- 题解 Fractal Streets
题目链接 参考博客 #include<cstdio> #include<math.h> #include<utility>//pair using namespac ...
- 升级openssh编译报错“configure: error: *** working libcrypto not found, check config.log”的解决办法
问题描述 在linux上,欲将OpenSSH_6.4p1编译升级到OpenSSH_8.0p1时,执行了./configure --prefix=/usr --sysconfdir=/etc/ssh - ...
- 直接打印类,调用toString()方法
直接打印类,调用的是继承的Object类的toString()方法,Object类的toString()方法是这样实现的:getClass().getName() + "@" + ...
- rancher版本问题引发的节点注册失败失败
rancher版本问题引发的节点注册失败失败 待办 https://www.cnblogs.com/Me1onRind/p/11147639.html
- Palindromes _easy version 题解
“回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串.请写一个程序判断读入的字符串是否是“回文”. Input输入包含多个测试实例,输入数据的第一行是一个正整数n ...
- Tex 一些命令
1. [!htp] 可以使这个内容跟随在前面的内容后面 假如前面是一段文字,后面是一幅图像,不知什么原因跑到其他地方去了.这时加个[!htp]可以使他紧紧跟在后面 ergdsgagdfgdfgfgaf ...
- python 小故事1
def test(a:str,b:int)->str: print(test.__annotations__) return a+str(b) def doc_print(): "&q ...