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题解的更多相关文章

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

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

  2. 刷题记录:Codeforces Round #719 (Div. 3)

    Codeforces Round #719 (Div. 3) 20210703.网址:https://codeforces.com/contest/1520. 没错,我是个做div3的蒟蒻-- A 大 ...

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

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

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

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

  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 #719 (Div. 3) C. Not Adjacent Matrix

    地址 Problem - C - Codeforces 题意 每个格子,该格子和相邻的格子的值不能相同 题解 思维题, 先从1~n输出奇数,再输出偶数 代码 #include <iostream ...

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

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

  10. 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 ...

随机推荐

  1. python中pip下载慢或报错的解决方法

    一:问题 python的pip在安装包时,有时会报错超时,排除包名写错的原因,一般这种问题是因为网络下载过慢,导致超时 二:解决方案 我们可以设置pip镜像源下载,能够提升pip下载速度,解决报错问题 ...

  2. 2023你需要使用的最佳VSCode扩展插件

    选择最佳的 Visual Studio Code(以下简称 VSCode) 扩展插件对于提高开发效率和改善编程体验非常重要. 下面将详细介绍一些广受欢迎且功能丰富的 VSCode 扩展插件,包括编辑器 ...

  3. MySQL日期时间加|减法

    日期加法 select date_add(curdate(), interval N SECOND); -- 加N秒 select date_add(curdate(), interval N MIN ...

  4. 【大语言模型基础】60行Numpy教你实现GPT-原理与代码详解

    写在前面 本文主要是对博客 https://jaykmody.com/blog/gpt-from-scratch/ 的精简整理,并加入了自己的理解. 中文翻译:https://jiqihumanr.g ...

  5. 支付宝 v3 验签如何实现

    上次给大家介绍了 支付宝 v3 自签名如何实现,这次顺便再把验签也写一下. 为什么要验签 说起为什么要验签,如果要详细一点解释的话,可以写很多很多...... 我们就简单一点来解释:验签可以证明接收到 ...

  6. dtd的三种引入方式

  7. BUUCTF-Crypto详细Writeup

    每一天都要努力啊    ----2024-01-01 18:11:36 1.一眼就解密 原题:下面的字符串解密后便能获得flag:ZmxhZ3tUSEVfRkxBR19PRl9USElTX1NUUkl ...

  8. .net Core中间件实战

    新建一个ASP.NET Core Web Application 项目选中空模板 然后为项目添加一个Microsoft.Extensions.Logging.Console 由于我用的.net cor ...

  9. Rabbitmq从安装到简单入门

    1:Rabbitmq是什么? RabbitMQ是实现了高级消息队列协议(AMQP)的开源消息代理软件(亦称面向消息的中间件). 它由以高性能.健壮以及可伸缩性出名的 Erlang 写成. 2:它的优点 ...

  10. 一颗红心,三手准备,分别基于图片(img)/SCSS(样式)/SVG动画实现动态拉轰的点赞按钮特效

    华丽炫酷的动画特效总能够让人心旷神怡,不能自已.艳羡之余,如果还能够探究其华丽外表下的实现逻辑,那就是百尺竿头,更上一步了.本次我们使用图片.SCSS样式以及SVG图片动画来实现"点赞&qu ...