写在前边

链接:Codeforces Round #701 (Div. 2)

数学场,题目描述简单粗暴,思路很妙,代码短的不行,都是好神奇的一些题目。

A. Add and Divide

链接:A题链接

题目大意:

给定两个正整数,我们可以进行两个操作:

  • \(a = \lfloor \frac{a}{b} \rfloor\)
  • \(b = b + 1\)

    最终目标是找到使\(a\)变成\(0\)的最小操作次数

思路

因为\(b\)每次只会变动\(1\),所以最开始思路就是,如果我们可以提前大体找到一个操作次数,我们在这个操作次数内进行枚举,而\(b\)每次操作只会变动\(1\),所以假设一共有\(sum\)次操作,如果我们可以有\(n\)次让\(b\)加\(1\),然后\(b\)变成了\(b + n\),然后让\(a\)不断的除\(b\)直到为\(0\),假设有\(m\)次操作,那么答案就是\(m + n\)次操作了,那么怎么才能找到这个\(sum\)呢,可以看数据范围,我们可以估计最差的情况,最差的情况就是当\(b=1,a = 10^9\)的时候,这时候我们首先要做的就是让\(b + 1\),然后再让\(a\)不断的除\(b\),直到为\(0\),而这最多需要\(\lfloor log_2(10^9) \rfloor = 29\)次,所以!经过分析最差情况也就进行\(30\)次操作左右,即\(m + n < 31\)所以我们只需要枚举到\(31\)即可,最坏情况\(O(log^2a)\)

代码:

#include <iostream>

#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring> using namespace std; #define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n' typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI; void solve() {
int a, b, res = 35;
cin >> a >> b;
if (a < b) {
puts("1");
return;
} for (int i = (b == 1 ? 1 : 0); i <= 30; i++) { //枚举多少次 最坏情况下就有30次
int tempa = a, tempres = i;
int tempb = b + i; while (tempa) {
tempa /= tempb;
tempres++;
}
res = min(res, tempres);
} cout << res << endl;
} int main()
{
//ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t;
scanf("%d", &t);
while (t--) {
solve();
}
system("pause");
return 0;
}

B. Replace and Keep Sorted

链接:B题链接

题目大意:

定义两个互为\(k-similar\)的数组:

  • 都是严格单调递增
  • 有相同的长度
  • 它们的元素范围\(\in [1, k]\)
  • 它们只有一个数不同。

现在给定一个数组\(a\),并且给定一个区间\([l,r]\),那么\(k-similar\)中的一个数组\(b_1\)就是\([a_l, a_{l + 1}, ... , a_r]\),长度为\(len = l - r + 1\) 那么另一个\(k-similar\)数组\(b_2\)就是可以从\([1, k]\)中选\(len\)个数,并且只与\(b_1\)有一个数不同的数组,问有多少个这样的数组\(b_2\)。

思路

首先想到可以挨个枚举每一个位置可以选多少个数,那么最终答案就是每一个位置可以选的数之和,但是这样数据范围就是\(O(q*n)\)明显会超时,所以就想能不能在\(O(1)\)复杂度之内就能判断出一个区间中所有的可能,第\(l\)个位置的数可以选\(a[l + 1] - 2\)个,第\(r\)个位置的数可以选\(k - a[r - 1] - 1\)个,对于\((l,r)\)(注意是开区间!)能选多少个我们可以用前缀和处理,前缀和就是每一个区间可以选择的数的个数,时间复杂度就降为了\(O(q)\).

代码:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring> using namespace std; #define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n' typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI; const int N = 1e5 + 10;
int a[N], b[N]; void solve() {
int n, k, q;
scanf("%d%d%d", &n, &q, &k);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]); a[n + 1] = k + 1;
for (int i = 1; i <= n; i++) {
b[i] += a[i + 1] - a[i - 1] - 2;
b[i] += b[i - 1];
} while (q--) {
LL res = 0;
int l, r;
scanf("%d%d", &l, &r);
res += b[r - 1] - b[l]; //开区间
res += k - a[r - 1] - 1; //右边
res += a[l + 1] - 2; //左边
printf("%d\n", res);
}
} int main()
{
//ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
solve(); return 0;
}

C. Floor and Mod

链接:C题链接

题目大意:

给定下下\(x,y\),现在要求求一个数对\((a, b)\),使得\(\lfloor \frac{a}{b} \rfloor = a \,\, mod \,\, b\), 要求\(a \in [1, x]\), \(b \in [1, y]\)。

思路

首先暴力肯定不行,所以想能不能用\(O(1)\)直接求出来,那只要推公式了,让\(\lfloor \frac{a}{b} \rfloor = a \,\, mod \,\, b = k\),所以推出\(a = k*b + k(b > k)\),又因为\(b > k\),可以推出\(k^2 < k*b+k = a \leq x\),所以\(k \leq \sqrt{x}\),所以现在求出了\(k\)的范围\(k \in [1, \sqrt{x}\,]\),现在要做的就是对于每一个固定的\(k\),如果我们可以推出\(a\)或者\(b\)数的范围,那么就可以求出数对\((a, b)\)可取的个数了,对于b,已知\(b > k\), \(1 \geq b \leq y\),根据 \(k*b+k = a \leq x\),得出\(b \leq x / k - 1\),因此得出\(b\)的个数就是\(max(0, min(y, x / k - 1) - k)\)。

代码:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring> using namespace std; #define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n' typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI; void solve() {
LL x, y;
cin >> x >> y; LL res = 0;
for (LL k = 1; k * k <= x; k++) {
res += max(0LL, min(y, x / k - 1) - k);
} cout << res << endl;
} int main()
{
//ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t;
scanf("%d", &t);
while (t--) {
solve();
}
system("pause");
return 0;
}

Codeforces Round #701 (Div. 2) A~C 题解的更多相关文章

  1. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  2. Codeforces Round #198 (Div. 2)A,B题解

    Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...

  3. Codeforces Round #672 (Div. 2) A - C1题解

    [Codeforces Round #672 (Div. 2) A - C1 ] 题目链接# A. Cubes Sorting 思路: " If Wheatley needs more th ...

  4. Codeforces Round #701 (Div. 2) 题解

    由于今天实在是太自闭了就前来写场已经 AK 的 div.2 的题解了 这场比赛是我的 div.2 首 AK 哦 A 先特判 \(b=1\),强制将 \(b+1\) 否则容易发现答案最大为 \(\log ...

  5. Codeforces Round #614 (Div. 2) A-E简要题解

    链接:https://codeforces.com/contest/1293 A. ConneR and the A.R.C. Markland-N 题意:略 思路:上下枚举1000次扫一遍,比较一下 ...

  6. Codeforces Round #610 (Div. 2) A-E简要题解

    contest链接: https://codeforces.com/contest/1282 A. Temporarily unavailable 题意: 给一个区间L,R通有网络,有个点x,在x+r ...

  7. Codeforces Round #611 (Div. 3) A-F简要题解

    contest链接:https://codeforces.com/contest/1283 A. Minutes Before the New Year 题意:给一个当前时间,输出离第二天差多少分钟 ...

  8. Codeforces Round #499 (Div. 2) D. Rocket题解

    题目: http://codeforces.com/contest/1011/problem/D This is an interactive problem. Natasha is going to ...

  9. Codeforces Round #499 (Div. 2) C Fly题解

    题目 http://codeforces.com/contest/1011/problem/C Natasha is going to fly on a rocket to Mars and retu ...

  10. Codeforces Round #198 (Div. 2)C,D题解

    接着是C,D的题解 C. Tourist Problem Iahub is a big fan of tourists. He wants to become a tourist himself, s ...

随机推荐

  1. python:时间模块dateutil

    安装 pip install python-dateutil dateutil模块主要有两个函数,parser和rrule. 其中parser是根据字符串解析成datetime,而rrule则是根据定 ...

  2. QPushButton中常用的方法

    常用方法如下所示: setCheckable():设置按钮是否已经被选中,如果设置为True,则表示按钮将保持已点击和释放状态. toggl():在按钮之间进行切换 setIcon():设置按钮上的图 ...

  3. SQL Server 内存占用较高 - 清除缓存 或 设置内存最大占用值

    SQL Server对服务器内存的使用策略是用多少内存就占用多少内存,只用在服务器内存不足时,才会释放一点占用的内存,所以SQL Server 服务器内存往往会占用很高 查看内存状态: DBCC Me ...

  4. 如何选择最适合您的Excel处理库?

    摘要:本文由葡萄城技术团队于博客园原创并首发.转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 引言 GcExcel和POI是两个应用于处理Excel文件的技 ...

  5. 使用MkDocs搭建个人博客

    使用MkDocs搭建个人博客 接触编程已经好几年了,阅读了无数大佬的博客文章,但是从来没有自己写过.这其中最重要的原因当然是懒惰,觉得写博客太费时间了,对自己的帮助也不大.可是如今发现自己的记性越来越 ...

  6. [loki]轻量级日志聚合系统loki快速入门

    前言 简述:loki是由grafana开源的日志聚合系统,相较于ELK.EFK更轻量. loki特性: 不对日志进行全文索引.通过存储压缩非结构化日志和仅索引元数据,Loki 操作起来会更简单,更省成 ...

  7. 带你快速上手HetuEngine

    本文分享自华为云社区<[手把手带你玩转HetuEngine](一)HetuEngine快速上手>,作者:HetuEngine九级代言. HetuEngine是什么 HetuEngine是华 ...

  8. Java NIO 图解 Netty 服务端启动的过程

    一.启动概述 了解整体Netty常用的核心组件后,并且对比了传统IO模式.在对比过程中,找到了传统IO对应Netty中是如何实现的.最后我们了解到在netty中常用的那些组件. 本文在了解下这些核心组 ...

  9. ThreadLocal:线程中的全局变量

    最近接了一个新需求,业务场景上需要在原有基础上新增2个字段,接口新增参数意味着很多类和方法的逻辑都需要改变,需要先判断是否属于该业务场景,再做对应的逻辑.原本的打算是在入口处新增变量,在操作数据的时候 ...

  10. 使用 Sealos 一键部署高可用 MinIO,开启对象存储之旅

    大家好!今天这篇文章主要向大家介绍如何通过 Sealos 一键部署高可用 MinIO 集群. MinIO 对象存储是什么? 对象是二进制数据,例如图像.音频文件.电子表格甚至二进制可执行代码.对象的大 ...