Codeforces Round #643 (Div. 2)

Sequence with Digits

思路

一道暴力题,猜想在某一步一定会出现0,于是怀着忐忑提交了代码,结果还真的是这样。

代码

#include <bits/stdc++.h>using namespace std;typedef long long ll;ll judge(ll x) {int minn = x % 10, maxn = x % 10;ll temp = x;temp /= 10;while(temp) {minn = min(int(temp % 10), minn);maxn = max(int(temp % 10), maxn);temp /= 10;}return x + minn * maxn;
}int main() {// freopen("in.txt", "r", stdin);int t;scanf("%d", &t);while(t--) {ll ans, n;scanf("%lld %lld", &ans, &n);for(ll i = 0; i < n - 1; i++) {ll temp = judge(ans);if(temp == ans) break;ans = temp;}printf("%lld\n", ans);}return 0;
}

Young Explorers

思路

应该是一个贪心吧。

题意是对于一个分数为eee的选手,只能加入人数大于等于eee的组里,所以我们取每一组的最大值刚好等于其人数,这样就最大化的利用了所有的人,当然进行这一步之前必须得先排序。

代码

#include <bits/stdc++.h>using namespace std;#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;const int N = 2e5 + 10;int a[N];int main() {// freopen("in.txt", "r", stdin);IOS;int t;cin >> t;// scanf("%d", &t);while(t--) {int n;cin >> n;for(int i = 0; i < n; i++)cin >> a[i];int sum = 0, ans = 0;sort(a, a + n);for(int i = 0; i < n; i++) {sum++;if(a[i] <= sum) {sum = 0;ans++;}}cout << ans << "\n";}return 0;
}

Count Triangles

思路

这题是看了别人的思路才写出来的,我一开始一直在枚举zzz边试图去找另外两条边的范围,但是一直wa。

  • 我们考虑枚举x+yx + yx+y的范围, min(c+1,a+b)<=i<=b+cmin(c + 1, a + b) <= i <= b + cmin(c+1,a+b)<=i<=b+c。
  • 通过x的最大值我们可以确定y的最小值,同时我们也可以通过x的最小值确定y的最大值。

当x=ax = ax=a,最大的ymax=min(i−a,c)y_{max} = min(i - a, c)ymax​=min(i−a,c),当y=by = by=b,最大的xmax=min(i−b,b)x_{max} = min(i - b, b)xmax​=min(i−b,b)

通过这个我们可以锁定任意的真正的最小的x∣∣yx || yx∣∣y,我们xmin=i−ymaxx_{min} = i - y_{max}xmin​=i−ymax​,ymin=i−xmaxy_{min} = i - x_{max}ymin​=i−xmax​

这里我们可以得到任意的一段符合条件的x,y的组合,num=(xmax−xmin+1)=(ymax−ymin+1)num = (x_{max} - x_{min} + 1) = (y_{max} - y_{min} + 1)num=(xmax​−xmin​+1)=(ymax​−ymin​+1)

然后zzz的取值区间长度是long=min(d−c+1,i−c)long = min(d - c + 1, i - c)long=min(d−c+1,i−c)。

我们每次枚举的区间答案就是ans+=num∗longans += num * longans+=num∗long

代码

#include <bits/stdc++.h>using namespace std;#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;int main() {// freopen("in.txt", "r", stdin);IOS;ll a, b, c, d, ans = 0;cin >> a >> b >> c >> d;for(int i = max(a + b, c + 1); i <= b + c; i++) {int x = min(i - b, b), y = min(i - a, c);x = i - x;ll l = min(i - c, d - c + 1);ans += l * (y - x + 1);}cout << ans << "\n";return 0;
}

Game With Array

思路

一道构造题,这题应该是比较好想的,当2∗n>s2 * n > s2∗n>s的时候,我们至少会出现两个一,然后剩下的全是2,这里我们显然可以得到我们所需要的和为sss的所有二进制数,所以这个是侯一定是不可能有解的。

当2∗n<=s2 * n <= s2∗n<=s的时候我们如何构造,只需要取n−1n - 1n−1个一,然后最后一个数是s−n+1s - n + 1s−n+1就行了,最后的kkk取nnn这样就可以保证答案的有解性。

代码

#include <bits/stdc++.h>using namespace std;#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;int main() {// freopen("in.txt", "r", stdin);IOS;int n, s;cin >> n >> s;if(2 * n > s)   cout << "NO\n";else {cout << "YES\n";for(int i = 0; i < n - 1; i++)cout << "1 ";cout << s - (n - 1) << "\n";cout << n << "\n";}// int t;// cin >> t;// // scanf("%d", &t);// while(t--) {// }return 0;
}

Restorer Distance

思路

因为push和move这两个操作,我们比较容易发现这两个操作好像在最大值最小值两头是等价的,因此当在最大最小值中间可能存在一个最优值,使操作成本最低。

通过上面的分析我们可以大致的得到这是一个凹函数,并且存在最极小值,因此我们可以考虑三分去的到这个最小值。

代码

#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N = 1e5 + 10;int a[N], n, A, R, M;ll f(int x) {ll sum1 = 0, sum2 = 0;//分别记录大于当前值的数量,和小于当前值的数量。for(int i = 1; i <= n; i++) {if(a[i] > x)    sum1 += a[i] - x;else if(a[i] < x)   sum2 += x - a[i];}ll ans = 0;ll mid = min(sum2, sum1);ans += mid * M;sum1 -= mid, sum2 -= mid;//优先考虑从一个移到另一个上。if(sum1)    ans += sum1 * R;if(sum2)    ans += sum2 * A;return ans;
}int main() {// freopen("in.txt", "r", stdin);scanf("%d %d %d %d", &n, &A, &R, &M);M = min(M, A + R);//这个操作可以等同是前两个操作的和,取一个最小值。for(int i = 1; i <= n; i++)scanf("%d", &a[i]);int l = 0, r = 1e9;while(l < r) {int lmid = l + (r - l) / 3;int rmid = r - (r - l) / 3;if(f(lmid) >= f(rmid))  l = lmid + 1;else    r = rmid - 1;}printf("%lld\n", min(f(l), f(r)));return 0;
}

Codeforces Round #643 (Div. 2)(A, B, C, D, E)相关推荐

  1. Codeforces Round #643 (Div. 2)——B. Young Explorers

    题目链接: https://codeforces.com/problemset/problem/1355/B 题目描述: 输入探险家的经验级别,组队时一个队伍的人数不能少于队伍中任一人的经验级别(人数 ...

  2. Codeforces Round #643 (Div. 2)B到C题解

    B. Young Explorers 题目大意:给你n个人,每个人都有不同的经验值,现在要将这些人分组,每个人可以加入该组的条件就是他的经验值小于等于他所在组的规模,要求组数最多,有的人可以不加组 解 ...

  3. Codeforces Round #643 (Div. 2)题解

    A . SequencewithDigitsSequence\ with\ DigitsSequence with Digits 首先数据范围就离谱,所以不管什么算法都不行,肯定是要找规律优化的. 我 ...

  4. Codeforces Round #643 (Div. 2)(AB)

    A: 思路:只有数字中出现0,那么后面就不会变动了.直接循环就可以,出现了0就退出. 代码如下: #include<bits/stdc++.h> #define ll long long ...

  5. Codeforces Round #643 (Div. 2)C

    题目链接 题意: x,y,z三个整数满足a<=x<=b<=y<=c<=z<=d,求出由边长x,y,z构成三角形的个数 题解: 设m=x+y,可知a+b≤ m ≤b+ ...

  6. Codeforces Round #643 (Div. 2) E. Restorer Distance 题解(三分)

    题目链接 题目大意 给你一个数组,要你使数组所有元素的值都相等且所消耗最小代价,增加1消耗a,减少1消耗r,转移1消耗m,求消耗最小代价 题目思路 如果增加减少都是1,转移是2,那么就是类似于仓库选址 ...

  7. Codeforces Round #643 (Div. 2) C. Count Triangles 题解(思维)

    题目链接 题目思路 显然是找x+y>z即可,其实只要枚举x+y即可,自己好菜qwq 代码 #include<cstdio> #include<algorithm> usi ...

  8. Codeforces Round #643 (Div. 2)-C. Count Triangles(差分,前缀和)(避免标题重复率的小括号)

    题目链接 题意: 给你a,b,c,d,保证a<=b<=c<=d,问你有多少个x,y,z符合a<=x<=b<=y<=c<=z<=d,并且x,y,z能 ...

  9. Codeforces Round #643 (Div. 2)

    这场是七点半的场,正好跑完步打了一下 于是: 害 还是太菜了 A - Sequence with Digits Let's define the following recurrence: an+1= ...

最新文章

  1. R语言多因素有交互方差分析(Two-Way ANOVA)实战:拟合多因素有交互方差分析模型、分析不同分组的差异TukeyHSD、多因素有交互方差分析的结果总结
  2. 网易云游戏来了:手机电脑电视随时接入可玩,高流畅度低延迟,还能跨终端无缝切换...
  3. 用 vue + d3 画一棵树
  4. 打造最好用的离线QQ截图工具 C#
  5. angular学习笔记(二十五)-$http(3)-转换请求和响应格式
  6. 【阿里云课程】卷积神经网络:结构单元、卷积层反向传播求解与典型模型
  7. 一个简单的高并发的回应服务器(5万并发)
  8. 【软件工程】实体类的持久性
  9. 李明顺专栏周5月12日:给门户支招
  10. 教你在CentOS 8上安装和配置Redmine项目管理系统
  11. Reacr-Native Android 环境搭建 、运行项目(二)Window
  12. 2021-10-11 全国大学生软件测试大赛赛前学习参考资料
  13. html5使用table制作表单
  14. vue3.0 watch监听器使用方法
  15. 对象存储、文件存储、块存储区别介绍
  16. 一、Java面试基础之面向对象的特征:继承、封装和多态(原创实例)
  17. Centos 7iso百度网盘下载
  18. IESM项目实训四——Web Audio录音和字符串转拼音
  19. 使用PHP实现图片上传
  20. Java集合中的fail-fast快速失败机制

热门文章

  1. 我们只知大势将至,却不知未来已来
  2. python怎么使用time模块_PYTHON的TIME模块使用
  3. python如何退出命令行_如何退出python命令行
  4. matlab浮点数求绝对值_MATLAB仿真阵列天线切比雪夫综合法(附代码)
  5. 项目进度计划甘特图_项目管理进度计划表制作及甘特图绘制方法
  6. 通过图书编号查询python_文字版图书管理-python练习
  7. 香肠派对电脑版_香肠派对先行服s7赛季下载-香肠派对先行服s7赛季最新版下载...
  8. 新华字典java_新华字典查询示例代码
  9. linux脚本传参修改配置文件,shell脚本修改配置文件指定行的值
  10. 算法题目——省份数量(dfs,bfs)