Codeforces Round #701 (Div. 2)赛后补题报告(A~D)

A. Add and Divide

原题信息

http://codeforces.com/contest/1485/problem/A

解题思路

对于题目基本有两种方式,一种是直接暴力求解,第二种是使用函数求导进行严格证明
暴力求解
a=1e9a=1e^9a=1e9不难看出,操作最多为 50次,因为249=5629499534213122 ^ 49 = 562949953421312249=562949953421312 直接就超了
那么我们的 bbb最多也就是加50次,然后进行向下整除的模拟即可
一定要注意 b=0b = 0b=0这种情况。
函数求导
首先我们设操作次数为yyy,进行 b+=1b += 1b+=1的次数为xxx,可以得到的关系式为
y=x+(logb+xa+1)y = x + (log_{b+x}a+1)y=x+(logb+x​a+1),其中logb+xalog_{b+x}alogb+x​a是整除到1的次数,最后 +1是让其变为0
下面我们对他进行求导
y′=1−lna(lnt)2⋅ty'=1-\frac{ln{a}}{(lnt)^2\cdot t}y′=1−(lnt)2⋅tlna​,其中t=b+x,t≥2并且t≥bt=b+x,t\geq2 并且 t\geq bt=b+x,t≥2并且t≥b
查看导函数的零点
(lnt)2⋅t=lna,t≥2并且t≥b{(lnt)^2\cdot t}=lna,t\geq2 并且 t\geq b(lnt)2⋅t=lna,t≥2并且t≥b,等式左侧递增,右侧为常数lnalnalna,即至多有一个零点
倘若有一个零点
可以直接二分求得零点,我们在零点,零点+1, 零点-1进行求解得结果。
倘若没有零点
直接就是t≥2并且t≥bt\geq2 并且 t\geq bt≥2并且t≥b取得最小值。

AC代码

首先必须吐嘲一下,暴力没往这个向限制,求导生疏了,整了半天,真鸡儿狗
暴力枚举代码

#include <bits/stdc++.h>
using namespace std;typedef long long LL;
const int N = 100010;LL a, b;int sol(LL a, LL b, int add)
{b += add;if (b == 1) return 0x3f3f3f3f;while (a){a /= b;add ++;}return add;
}int main()
{int T;  cin >> T;while (T -- ){scanf("%lld%lld", &a, &b);int res = 1000;for (int i = 0; i <= 50; i ++ ){res = min(res, sol(a, b, i));}cout << res << endl;}return 0;
}

函数求导代码

#include <bits/stdc++.h>
using namespace std;const int N = 100010;
typedef long long LL;
const double esp = 1e-5;
LL a, b;int RealDo(LL a, LL b)
{int ret = 0;while (a){ret ++;a /= b;}return ret;
}int Get(LL a, LL b, LL tarb)
{if (tarb <= 1 || tarb < b)  return 0x3f3f3f3f;// return (tarb - b) + floor(log(a) / log(tarb)) + 1;return (tarb - b) + RealDo(a, tarb);
}double Cal(LL a, LL b)
{double lga = log(a);double l = b, r = 2e9, mid = b;if (lga <= mid * (log(mid) * log(mid)) )    // 不用加return mid;while (abs(l - r) >= esp){mid = (l + r) / 2;if (lga <= mid * (log(mid) * log(mid))) // 高了r = mid;else    // 低了l = mid;}return mid;
}int sol(LL a, LL b)
{double x = Cal(a, b);return min(Get(a, b, x), min(Get(a, b, x + 1), Get(a, b, x - 1)));
}int main()
{int t;cin >> t;while (t -- ){scanf("%lld%lld", &a, &b);cout << sol(a, b) << endl;}return 0;
}

B. Replace and Keep Sorted

原题信息

http://codeforces.com/contest/1485/problem/B

解题思路

我们单独考虑端点的可能性,已经中间结点不同的次数(可以使用前缀和)
但是一定要仔细考虑什么时候 + 1,什么时候没有+1, 端点是否包括

AC代码

#include <bits/stdc++.h>
using namespace std;const int N = 100010;
int n, k, q;
int a[N];
int b[N];int cal(int l, int r)
{if (l == r) return  k - 1;else{int ret = (a[l] - 1) + (a[l + 1] - a[l] - 1) + (k - a[r]) + (a[r] - a[r - 1] - 1);if (l == r - 1)return ret;elsereturn ret + b[r - 1] - b[l];   // l + 1 ~ r - 1}
}
int main()
{cin >> n >> q >> k;for (int i = 1; i <= n; i ++ )scanf("%d", &a[i]);memset(b, 0, sizeof b);for (int i = 2; i <= n - 1; i ++ )b[i] = (a[i] - a[i - 1] - 1) + (a[i + 1] - a[i] - 1);for (int i = 2; i <= n - 1; i ++ )b[i] += b[i - 1];while (q -- ){static int l, r;scanf("%d%d", &l, &r);// cout << "res" << endl << "\t";cout << cal(l, r) << endl;}return 0;
}

C. Floor and Mod

原题信息

http://codeforces.com/contest/1485/problem/C

解题思路

C题吐槽一下,当时复杂度分析错了,O(N)O(\sqrt N)O(N​)分析成O(N)O(N)O(N),太绝了
设⌊ab⌋=a%b=t,t<b\lfloor\frac a b\rfloor=a\%b=t, t< b⌊ba​⌋=a%b=t,t<b
那么a=t⋅b+t=(b+1)⋅t,A≥a≥1,B≥b≥1a=t \cdot b + t=(b+1)\cdot t, A\geq a\geq1,B\geq b\geq1a=t⋅b+t=(b+1)⋅t,A≥a≥1,B≥b≥1

  • 当t=1t=1t=1时,a=b+1,b∈[2,B]a=b+1,b\in [2, B]a=b+1,b∈[2,B]
  • 当t=2t=2t=2时,a=2⋅(b+1),b∈[3,B]a=2\cdot(b+1),b\in [3, B]a=2⋅(b+1),b∈[3,B]
  • 当t=it=it=i时,a=i⋅(b+1),b∈[i+1,B]a=i\cdot(b+1),b\in [i + 1, B]a=i⋅(b+1),b∈[i+1,B]
    此时,i⋅(b+1)≤A,b≤B,b≥i+1i \cdot (b + 1)\leq A, b\leq B, b\geq i+1i⋅(b+1)≤A,b≤B,b≥i+1
    ⟹b∈[i+1,min(B,⌊Ai⌋−1)]\Longrightarrow b\in [i + 1, min(B,\lfloor \frac A i \rfloor-1)]⟹b∈[i+1,min(B,⌊iA​⌋−1)]
    如果⌊Ai⌋−1\lfloor \frac A i \rfloor-1⌊iA​⌋−1有前缀和公式的话,是可以进行化简为O(1)O(1)O(1)的
    最后,b∈[i+1,min(B,⌊Ai⌋−1)]b\in [i + 1, min(B,\lfloor \frac A i \rfloor-1)]b∈[i+1,min(B,⌊iA​⌋−1)]可以看出来iii的最大值,是无法取到1e91e91e9的,需要开个根号。

AC代码

#include <bits/stdc++.h>
using namespace std;typedef long long LL;void Sol(LL A, LL B)
{LL a, b, tmp, ret = 0;for (int i = 1; true; i ++ ){tmp = min(B, A / i - 1);// i + 1 ~ tmpif (i + 1 > tmp)    break;else    ret += (tmp - (i + 1) + 1);}cout << ret << endl;
}int main()
{int t;  cin >> t;while (t -- ){static LL a, b;scanf("%lld%lld", &a, &b);Sol(a, b);}return 0;
}

D. Multiples and Power Differences

原题信息

http://codeforces.com/contest/1485/problem/D

解题思路

可恶啊,这个题目是一个LCM的板子题,没看出来。。。
首先,我们对1~16求LCM = x,我们的 B 数组首先全是x,可以满足multiplemultiplemultiple的性质,然后我们凑性质三,发现可以直接进行隔项加上ai,j4a_{i, j}^4ai,j4​,而且数据范围小,满足性质1

AC代码

#include <bits/stdc++.h>
using namespace std;typedef long long LL;
const int N = 510;
int n, m;
int a[N][N];
int b[N][N];int gcd(int x, int y)
{if (y == 0) return x;else    return gcd(y, x % y);
}int lcm(int x, int y)
{return LL(x) * y / gcd(x, y);
}int main()
{cin >> n >> m;for (int i = 1; i <= n; i ++ )for (int j = 1; j <= m; j ++ )scanf("%d", &a[i][j]);int x = 1;for (int i = 1; i <= 16; i ++ ){x = lcm(x, i);}for (int i = 1; i <= n; i ++ )for (int j = 1; j <= m; j ++ )b[i][j] = x;for (int i = 1; i <= n; i ++ ){for (int j = (i % 2 == 1 ? 1 : 2); j <= m; j += 2){b[i][j] += (a[i][j] * a[i][j]) * (a[i][j] * a[i][j]);}}// outputfor (int i = 1; i <= n; i ++ ){printf("%d", b[i][1]);for (int j = 2; j <= m; j ++ )printf(" %d", b[i][j]);puts("");}return 0;
}

总结

  • 首先考虑暴力,能否直接缩小范围,省时间
  • 其次,考虑复杂度的时候,分析准确一些
  • 多考虑边界的情况,+1,-1
  • 最后题型要把握清楚,数据范围小的时候,有时候会暴力,有时候直接lcm。。。

Codeforces Round #701 (Div. 2)赛后补题报告(A~D)相关推荐

  1. Codeforces Round #498 (Div. 3) - 赛后补题

    D. Two Strings Swaps PS:没思考清楚,重复算了一些情况. #include<bits/stdc++.h> #include<bitset> #define ...

  2. Codeforces Round #750 (Div. 2)A-F1补题题解

    A **题目描述:**有 a 首 1分钟的歌,b 首 2 分钟的歌,c首 3 分钟的歌.要分在两场音乐会,问最小的差是多少. 这道题的关键是题上说a,b,c,均不为0,这样的话三种歌总能被独立的分在两 ...

  3. Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...

  4. Codeforces Round #700 (Div. 2)A~D2解题报告

    Codeforces Round #700 (Div. 2)A~D2解题报告 A Yet Another String Game 原题链接 http://codeforces.com/contest/ ...

  5. Codeforces Round #693 (Div. 3)A~G解题报告

    Codeforces Round #693 (Div. 3)A~G解题报告 A Cards for Friends 原题信息 http://codeforces.com/contest/1472/pr ...

  6. Codeforces Round #697 (Div. 3)A~G解题报告

    Codeforces Round #697 (Div. 3)A~G解题报告 题 A Odd Divisor 题目介绍 解题思路 乍一想本题,感觉有点迷迷糊糊,但是证难则反,直接考虑没有奇数因子的情况, ...

  7. Codeforces Round #828 (Div. 3)-赛后总结

    Dashboard - Codeforces Round #828 (Div. 3) - Codeforces 打完比赛的晚上美滋滋的看着解出来的六道题,心想着能够加上一百多分.一觉醒来眼睁睁看着E1 ...

  8. Codeforces Round #673 (Div. 2)——待补 E

    由于开学了,一般晚上就不打cf了(太晚了,寝室不太适合打),而且赛后也懒得vp,有时候会在图书馆口胡题目,然后回寝室补一补,不过我也写得太久了吧,很多细节疯狂wa A - Copy-paste 不难发 ...

  9. Codeforces Round #727 (Div. 2) A~D题

    Codeforces提交链接 A题:Contest Start 题意: k组样例. 每行3个整数,n,x,t. n个人考试. 第1个人在 0 时刻开始考试, 第2个人在 x 时刻开始考试, 第3个人在 ...

最新文章

  1. apache起步命令加-k参数和不加的区别
  2. Orchard:使用VS2010来生成一个地图Content Part
  3. 假笨说-协助美团kafka团队定位到的一个JVM Crash问题
  4. 1.2.2 OSI参考模型(1)
  5. js处理16进制hex转str出现的中文乱码问题
  6. 取某个字段的前几位 php,php如何实现截取前几个字符
  7. python之强化学习入门
  8. 课程设计:混合数据排序
  9. PECL PEAR php扩展模块的简便安装方式
  10. 怎么设置某个用户生成hdfs文件的权限_管理 HDFS 服务
  11. rainmeter皮肤编写教程
  12. Docker日志查看命令
  13. 这几个好用的简单流程图模板,你可不能错过
  14. vipkid、哒哒英语、vipjr在线英语品牌投资回报率哪个高?
  15. 征途mysql启动不了_mysql无法启动
  16. java web 站内信 设计
  17. Revit二次开发——图元(元素)编辑
  18. ovn 通过网关虚拟路由器连接外部网络
  19. 使用Apache Solr对数据库建立索引(包括处理CLOB、CLOB)(转)
  20. 今日雨水——草木萌動

热门文章

  1. Hbase Rowkey设计原则
  2. 超乎想象,数据揭示自学成才的码农为何备受青睐
  3. 洛谷树剖模板题 P3384 | 树链剖分
  4. 【NS2】在linux下安装低版本GGC
  5. sql server :distinct 与order by 一起使用要注意
  6. Linux Cpu 利用率计算
  7. 常见单元测试工具介绍
  8. 90后中国程序员“黑吃黑”博彩网站,半年获利256万,判刑11年半
  9. 实现Linux系统的回收站
  10. AfxGetMainWnd( )函数