Codeforces Round #719 (Div. 3) A~E题解
51鸽了几天,有几场比赛的题解还没发布,今天晚上会补上的
1520A. Do Not Be Distracted!
问题分析
模拟,如果存在已经出现的连续字母段则输出NO
using ll = long long;
void solve() {
int n;
string s;
cin >> n >> s;
bool vis[30] = {false};
for (int i = 0; i < n; ++i) {
if (vis[s[i] - 'A']) {
cout << "NO\n";
return;
}
int j = i;
while (s[j] == s[i]) j++;
vis[s[i] - 'A'] = true;
i = j;
}
cout << "YES\n";
}
1520B. Ordinary Numbers
using ll = long long;
bool check(int x) {
string temp = to_string(x);
for (int i = 0; i < temp.size() - 1; i++)
if (temp[i] != temp[i + 1]) return false;
return true;
}
ll ans;
void solve() {
ll n;
cin >> n, ans = 0;
int k = 1, temp = 1;
for (int i = temp; i <= n; i += temp) {
if (check(i)) ans++;
else {
temp = temp * 10 + 1;
i = 0;
}
}
cout << ans << endl;
}
1520C. Not Adjacent Matrix
问题分析:构造思想
- \(n = 2\) ,无论怎么构造矩阵都会产生相邻的矩阵。
- 其他情况,以 \(1\) 为起点每次间隔 + 2,因为 数值不超过 \(n * n\) 所以,在大于此值时再从 \(2\) 开始枚举,这样一定能填充整个 \(n * n\) 矩阵
void solve() {
int n;
cin >> n;
vector<int> a(100 * 100 + 10);
if (n == 2) {
cout << -1 << "\n";
return;
}
int cnt = 1;
for (int i = 1; i <= n * n; ++i) {
if (cnt <= n * n) a[i] = cnt, cnt += 2;
if (cnt > n * n) cnt = 2;
}
for (int i = 1; i <= n * n; ++i) {
cout << a[i];
if (i % n == 0) cout << "\n";
else
cout << " ";
}
}
1520D. Same Differences
问题分析
变换公式,\(a_j - a_i = j - i \to a_j - j = a_i - i\)
所以我们可以存储 \(a_x - x\) 的值,然后进行组合数计算 \(C_m^2\) ,\(m\) 代表 \(a_x - x\) 的个数
using ll = long long;
void solve() {
int n;
map<int, ll> mp;
cin >> n;
for (ll i = 1, x; i <= n; ++i) {
cin >> x;
mp[x - i]++;
}
ll cnt = 0;
for (auto p : mp) cnt += p.second * (p.second - 1) / 2;
cout << cnt << "\n";
}
1520E. Arranging The Sheep
问题分析:贪心
对于绵羊序列,两端都往中间移动一定最优
void solve() {
int n;
string s;
cin >> n >> s;
vector<int> a;
int empty = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == '.') empty++;
else
a.push_back(empty);
}
int mid = (a.size() - 1) >> 1;
ll ans = 0;
for (auto x : a) ans += abs(x - a[mid]);
cout << ans << "\n";
}
1520F1. Guess the K-th Zero (Easy version)
// 待补
Codeforces Round #719 (Div. 3) A~E题解的更多相关文章
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- 刷题记录:Codeforces Round #719 (Div. 3)
Codeforces Round #719 (Div. 3) 20210703.网址:https://codeforces.com/contest/1520. 没错,我是个做div3的蒟蒻-- A 大 ...
- Codeforces Round #198 (Div. 2)A,B题解
Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...
- Codeforces Round #672 (Div. 2) A - C1题解
[Codeforces Round #672 (Div. 2) A - C1 ] 题目链接# A. Cubes Sorting 思路: " If Wheatley needs more th ...
- Codeforces Round #614 (Div. 2) A-E简要题解
链接:https://codeforces.com/contest/1293 A. ConneR and the A.R.C. Markland-N 题意:略 思路:上下枚举1000次扫一遍,比较一下 ...
- Codeforces Round #610 (Div. 2) A-E简要题解
contest链接: https://codeforces.com/contest/1282 A. Temporarily unavailable 题意: 给一个区间L,R通有网络,有个点x,在x+r ...
- Codeforces Round #611 (Div. 3) A-F简要题解
contest链接:https://codeforces.com/contest/1283 A. Minutes Before the New Year 题意:给一个当前时间,输出离第二天差多少分钟 ...
- Codeforces Round #719 (Div. 3) C. Not Adjacent Matrix
地址 Problem - C - Codeforces 题意 每个格子,该格子和相邻的格子的值不能相同 题解 思维题, 先从1~n输出奇数,再输出偶数 代码 #include <iostream ...
- Codeforces Round #499 (Div. 2) D. Rocket题解
题目: http://codeforces.com/contest/1011/problem/D This is an interactive problem. Natasha is going to ...
- 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 ...
随机推荐
- Modbus 转PROFIBUS DP网关在工厂自动温度控制系统中的应用案例
Modbus 转PROFIBUS DP 网关PM-160 在工厂自动温度控制系统中的应用案例 摘要 随着科技的发展和工业生产水平的提高,自动温度控制系统在纺织.化工.机械等各类工业控制过程中得到了广泛 ...
- Educational Codeforces Round 101 (Rated for Div. 2) E - A Bit Similar
题目传送门 很巧妙的一道题.对于一个 \(n\)位的 \(01\)字符串,一共有 \(2^n\)种不同字符排列,对于任意一个固定排列,在 \(2^n\)种排列中只有一种排列与该固定排列处处不等,而题干 ...
- 【UniApp】-uni-app-扩展组件
前言 好,经过上个章节的介绍完毕之后,了解了一下 uni-app-内置组件 那么了解完了uni-app-内置组件之后,这篇文章来给大家介绍一下 UniApp 中的扩展组件 首先不管三七二十一,先来新建 ...
- jdk21的外部函数和内存API(MemorySegment)(官方翻译)
1.jdk21: 引入一个 API,通过该 API,Java 程序可以与 Java 运行时之外的代码和数据进行互操作.通过有效地调用外部函数(即JVM外部的代码)和安全地访问外部内存(即不由JVM ...
- [ARC145D] Non Arithmetic Progression Set
Problem Statement Construct a set $S$ of integers satisfying all of the conditions below. It can be ...
- [ABC265F] Manhattan Cafe
Problem Statement In an $N$-dimensional space, the Manhattan distance $d(x,y)$ between two points $x ...
- PyTorch 实战(模型训练、模型加载、模型测试)
本次将一个使用Pytorch的一个实战项目,记录流程:自定义数据集->数据加载->搭建神经网络->迁移学习->保存模型->加载模型->测试模型 自定义数据集 参考我 ...
- java.lang.TypeNotPresentException: Type javax.servlet.http.HttpServletRequest not present
完整的报错信息 java.lang.TypeNotPresentException: Type javax.servlet.http.HttpServletRequest not present at ...
- 前端异步编程 —— Promise对象
在前端编程中,处理一些简短.快速的操作,在主线程中就可以完成. 但是,在处理一些耗时比较长以至于比较明显的事情,比如读取一个大文件或者发出一个网络请求,就需要异步编程来实现,以避免只用主线程时造成页面 ...
- Vue3节流指令封装
节流指令 import { ObjectDirective } from 'vue' interface ThrottleEl extends HTMLElement { throttleEvent: ...