Codeforces Round #701 (Div. 2) A. Add and Divide
2021/8/17 23:07:56
本文主要是介绍Codeforces Round #701 (Div. 2) A. Add and Divide,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
题目链接
目录- 题目大意
- 题目分析
- AC代码
题目大意
给你两个数字\(a\)和\(b\),让你执行两种操作:
- \(a=\lfloor \frac{a}{b}\rfloor\)
- \(b=(b+1)\)
问你最少需要几次操作,让\(a\)变成\(0\)
题目分析
当\(a=10^9,b=1\)的极限情况下,最少操作次数不超过20次,之后再去暴力枚举在20次操作内,经过上述两种操作让\(a=0\)最少需要几次操作。同时,需要注意,当\(b\le1\)的时候是没有什么判断价值的,因为这个时候再去执行\(\lfloor \frac{a}{b}\rfloor\)的次数肯定是最多的。
AC代码
#include <iostream> #include <algorithm> using namespace std; int t, a, b; inline int f(int A, int B) { int res = 0; while (a) { a /= b; res++; } return res; } int main() { scanf("%d", &t); while (t --) { scanf("%d%d", &a, &b); int res = 0x3f3f3f3f; for (int i = 0; i < 20; i++) { if (b + i <= 1) continue; res = min(res, f(a, b + i) + i); } cout << res << '\n'; } return 0; }
这篇关于Codeforces Round #701 (Div. 2) A. Add and Divide的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-15PingCAP 黄东旭参与 CCF 秀湖会议,共探开源教育未来
- 2024-05-13PingCAP 戴涛:构建面向未来的金融核心系统
- 2024-05-09flutter3.x_macos桌面os实战
- 2024-05-09Rust中的并发性:Sync 和 Send Traits
- 2024-05-08使用Ollama和OpenWebUI在CPU上玩转Meta Llama3-8B
- 2024-05-08完工标准(DoD)与验收条件(AC)究竟有什么不同?
- 2024-05-084万 star 的 NocoDB 在 sealos 上一键起,轻松把数据库编程智能表格
- 2024-05-08Mac 版Stable Diffusion WebUI的安装
- 2024-05-08解锁CodeGeeX智能问答中3项独有的隐藏技能
- 2024-05-08RAG算法优化+新增代码仓库支持,CodeGeeX的@repo功能效果提升