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 ...
随机推荐
- LOG日志系统
# coding=utf-8 import datetime import logging import os import sys from logging.handlers import Time ...
- 【uniapp】【外包杯】学习笔记day06 | 微信小程序导航栏的制作并推送的到码云【黑】
先创建分支 格式化快捷键 shift+alt+f
- .NET周刊【11月第4期 2023-11-26】
国内文章 万字长文:从 C# 入门学会 RabbitMQ 消息队列编程 https://www.cnblogs.com/whuanle/p/17837034.html 如题,详细的介绍RabbitMQ ...
- Django学习(二) 之 模板的使用
写在前面 昨晚应该是睡的最好一天吧,最近一个月睡眠好差,睡不着不说,而且半夜总醒,搞的第二天就会超没精神. 昨天下午去姐姐家,小外甥直接进屋就问我说: 老舅,你都很长时间没来啦,**(前女友)怎么哪去 ...
- Protobuf的使用,结合idea
安装Protobuf并配置idea Protocol Buffers(又名 protobuf)是 Google 的中立语言, 平台中立.可扩展的结构化数据序列化机制. 官网: https://gith ...
- vue-test4 -------组件之间的数据传递
<template> <h3>CompA</h3> <component-b :onfun="dateFun"></compo ...
- HBase应用方案
HBase性能优化方法:
- MinIO入门
MinIO 是一种高性能.S3 兼容的对象存储. 官方资料 中国官网 代码仓库 安装和部署MinIO 单节点单硬盘部署MinIO 单节点多硬盘部署MinIO 多节点多硬盘部署 站点复制概述 管理现有的 ...
- libGDX游戏开发之字体样式(七)
libGDX游戏开发之字体样式(七) libGDX系列,游戏开发有unity3D巴拉巴拉的,为啥还用java开发?因为我是Java程序员emm-国内用libgdx比较少,多数情况需要去官网和googl ...
- 14、Flutter Card卡片组件
Card是卡片组件块,内容可以由大多数类型的Widget构成,Card具有圆角和阴影,这让它看起来有立 体感. Card实现一个通讯录的卡片 class MyApp2 extends Stateles ...