Educational Codeforces Round 100 (Rated for Div. 2)
文章目录
- Educational Codeforces Round 100 (Rated for Div. 2)
- A. Dungeon
- B. Find The Array
- C. Busy Robot
- D. Pairs
Educational Codeforces Round 100 (Rated for Div. 2)
A. Dungeon
题意: 给你a、b、c三个数,你每次操作可以选择其中一个数减去1,每逢7的倍数次操作,三个数都减去1。问是否可以在某一轮三个数同时变成零。
题解: 只需要判断hp的和十分为9的倍数,且判断3个怪物是否都能活得那个回合即可。
代码:
#include <bits/stdc++.h>using namespace std;const int N = 1e3 + 5;
typedef long long LL;
int n;
int main() {cin >> n;while (n--) {LL Sum = 0;LL a, b, c;cin >> a >> b >> c;Sum = a + b + c;if (Sum % 9 == 0 && (min(a, min(b, c)) >= (Sum / 9)))puts("YES");elseputs("NO");}return 0;
}
B. Find The Array
题意: 构造b数组,使得相邻b数组元素互相整除,然后ai和bi的差值的绝对值的累加和的2倍小于等于S。S为a的和
题解: 因为b元素互相整除,猜想b数组为1,或者中位数、平均数、2的幂次,可以证明2的幂次这个方案是对的。只需要取b数组是距离ai最近的2的幂次即可。
代码:
#include <bits/stdc++.h>using namespace std;const int N = 1e6 + 5;
typedef long long LL;
int t, n;
LL a[40];
LL x;
int main() {for (int i = 0; i <= 33; i++) {a[i] = 1 << i;}scanf("%d", &t);while (t--) {scanf("%d", &n);while (n--) {scanf("%d", &x);int pos = upper_bound(a, a + 34, x) - a;printf("%d ", a[pos - 1]);}cout << endl;}return 0;
}
C. Busy Robot
题意: 有个机器人,在数轴上移动,你给出 (ti,xi) 的指令,代表指令下达的时间和需要他移动到的位置。收到指令以后机器人会以1的速度移动。如果下达指令时机器人在运动中则忽略当下指令。一个指令 i 是成功的当 ti 到 t(i+1) 的时间 内机器人有出现在 xi 位置过。 现在让你计算成功的指令的数量。
题解: 直接模拟
代码:
#include <bits/stdc++.h>const int maxn = 2e5 + 4;using namespace std;int n, T;
int mid[maxn], cm[maxn], l[maxn];int main() {scanf("%d", &T);while (T--) {memset(mid, 0, sizeof mid);memset(cm, 0, sizeof cm);memset(l, 0, sizeof l);scanf("%d", &n);int min = 0, max = 0, tig = 0, last = 0;for (int i = 1; i <= n; i++) {scanf("%d%d", &mid[i], &cm[i]);if (abs(cm[last] - l[last]) <= mid[i] - mid[last]) {l[i] = cm[last];last = i;} else {if (cm[last] > l[last]) {l[i] = l[last] + mid[i] - mid[last];} else{ l[i] = l[last] - mid[i] + mid[last]; }}}l[n + 1] = cm[last];int cnt = 0;for (int i = 1; i <= n; i++) {if ((cm[i] <= l[i] && cm[i] >= l[i + 1] ) ||(cm[i] <= l[i + 1] && cm[i] >= l[i])) {cnt++;}}printf("%d\n", cnt);}return 0;
}
D. Pairs
题意: 有1~2n个整数,两两匹配,得到n个分组。其中有x组取max,剩下n-x组取min。问有多少种x的取值,使得得到的新的数组是b数组。1<=n<=1051 <=n<=10^51<=n<=105
题解: 容斥+二分+贪心。贪心地想,对于当前元素,如果我们使得它是取min留下的,那么我们选择的数字要选择比它大的尽可能小的数字和它配对,这样就能够留下较大的数字去取max;如果我们使得它是取max留下的,那么我们选择的数字是比它小的最大的数字和它配对,这样就能够留下较小的数字去取min。所以我们可以不断去找对于当前数字,是否能够作为max或者min,记录这个值分别为R和L。我们可以使用set将可以使用的数字存储下来,然后寻找时使用二分查找即可。那么根据容斥原理,R+L-n就是既能够当max也能够当min的个数,因此方案数就是R+L-n+1(意为我们可以选择0~R+L-n个数字进行划分)。
代码:
#include <bits/stdc++.h>using namespace std;#define int long long
const int MAXN = 4e5 + 10;
int b[MAXN], vis[MAXN];signed main() {int t;cin >> t;while (t--) {int n;cin >> n;for (int i = 1; i <= n * 2; i++) vis[i] = 0;for (int i = 1; i <= n; i++) {cin >> b[i];vis[b[i]] = 1;}set<int> s1, s2;for (int i = 1; i <= n * 2; i++) {if (!vis[i]) {s1.insert(i);s2.insert(i);}}int l = 0, r = 0;for (int i = 1; i <= n; i++) {auto it1 = s1.upper_bound(b[i]); // 找到大于等于b的数字if (it1 != s1.end()) {s1.erase(it1);r++;}auto it2 = s2.upper_bound(b[i]);if (it2 != s2.begin()) {it2--; // 找到小于b的最大数字s2.erase(it2);l++;}}cout << r + l - n + 1 << '\n'; // 容斥:答案就是既能够当大也能够当小的个数+1}return 0;
}
Educational Codeforces Round 100 (Rated for Div. 2)相关推荐
- Educational Codeforces Round 100 (Rated for Div. 2)补题记录
总结:感觉这个educational场好难啊(蒟蒻视角),又被虐了,唉 A. Dungeon 每一枪会造成1点伤害对一个单位,但是当开7的倍数枪时会造成3点伤害 每7次一个轮回,一个完整的轮回共造成9 ...
- Educational Codeforces Round 89 (Rated for Div. 2)(A, B, C, D)
Educational Codeforces Round 89 (Rated for Div. 2) A. Shovels and Swords 思路 题意非常简单,就是得到最多的物品嘛,我们假定a, ...
- Educational Codeforces Round 121 (Rated for Div. 2) unr场 A B C
Educational Codeforces Round 121 (Rated for Div. 2) A B C A. Equidistant Letters 思路: 每个字母在里面出现不超过两次且 ...
- Educational Codeforces Round 123 (Rated for Div. 2) 简训
Educational Codeforces Round 123 (Rated for Div. 2)简训 导语 涉及的知识点 题目 A Doors and Keys B Anti-Fibonacci ...
- Educational Codeforces Round 138 (Rated for Div. 2)-赛后总结
Dashboard - Educational Codeforces Round 138 (Rated for Div. 2) - Codeforces 总结一个教训就是不要心急,特别是对于一些题目, ...
- Educational Codeforces Round 138 (Rated for Div. 2) A~D
比赛链接:Dashboard - Educational Codeforces Round 138 (Rated for Div. 2) - Codeforces 目录 A. Cowardly Roo ...
- Educational Codeforces Round 103 (Rated for Div. 2)
Educational Codeforces Round 103 (Rated for Div. 2) http://codeforces.com/contest/1476 A K-divisible ...
- Educational Codeforces Round 104 (Rated for Div. 2)A-E题解
Educational Codeforces Round 104 (Rated for Div. 2)A-E题解 比赛链接:https://codeforces.ml/contest/1487 A题 ...
- Educational Codeforces Round 103 (Rated for Div. 2)前四题
Educational Codeforces Round 103 (Rated for Div. 2) 第二次被别人hack,悲 A - K-divisible Sum 题意 给定两个整数 n,kn, ...
最新文章
- SharePoint Server 2013 之四:部署SharePoint企业版
- 第二十篇:Summarisation摘要
- SpringCloud之分布式配置中心(六)
- 【 MATLAB 】信号处理工具箱之波形产生函数 tripuls
- 我的世界minecraft-Python3.9编程(2)-开发环境配置(2)
- Traveling on the Axis (The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online)
- ndtmapping建图_自动驾驶系列:激光雷达建图和定位(NDT)
- 计算机的英语对话,英语口语对话:谈论电脑
- 问题记录:既然MAC能唯一标识一台设备,那为什么我们还需要IP呢?
- SharePoint 2010 价格计算器
- Ubuntu添加开机自动运行程序
- 张正友相机标定全解析
- python日程表代码_【算法提高班】《我的日程安排表》系列
- Mac电脑常见问题解答
- woc,又一个大佬辞职了……
- Consul + fabio 实现自动服务发现、负载均衡 1
- 计算机网络按分布范围分类可分为局域网,计算机网络按照覆盖范围可以分为局域网...
- js如何获取当天开始时间和结束时时间并传递(时间戳)给后端
- 在c语言中出现的int错误类型,【揭秘】C语言类型转换时发生了什么?
- UVA 12325 Zombie's Treasure Chest
热门文章
- Python学习-Matplotlib库绘制简单点阵图、线型图操作
- 一个CSDN程序员苦逼的一天又一天——part2
- Starting nodemanagerslocalhost: mv: 无法获取‘/opt/module/hadoop-3.1.3/logs/hadoop-atguigu-nodemanager-ha
- 破解山东网通adsl共享封杀
- UML各种模板图型汇总大全,教你轻松画!
- 无纸化手写电子签名是现今不可或缺的技术
- TvInput Cec key事件传递流程
- 现代信号处理——参数估计理论(最小二乘估计)
- 机器人辅助的符文天赋_LOLS7辅助机器人 机器人辅助天赋加点攻略
- Swiper的API及自定义分页器等问题-淘宝触屏版首页制作