Educational Codeforces Round 99 (Rated for Div. 2)

A. Strange Functions

读懂题即可(或者快速看一下样例解释),直接输出字符串长度即可。

void solve() {
string s;
cin >> s;
cout << s.length() << endl;
}

B. Jumps

这是一个数轴移动问题,按题意推导一下就好

void solve() {
int x; cin >> x;
int cnt = 0;
while (cnt * (cnt + 1) < (x << 1)) cnt++;
if (cnt * (cnt + 1) / 2 == x + 1) cnt++;
cout << cnt << endl;
}

C. Ping-pong

题意是Alice 和 Bob 开始玩击球游戏,但他们只有 x 和 y 个体力,每次发球和击回都要消耗一点体力,问怎么应对才能使两方的赢数最大

根据样例解释,其实对Bob而言只要我不回第一球,那么后面都会是Bob赢。那么就很简单了,次数为 \(x - 1, y\)

void solve() {
int x, y;
cin >> x >> y;
cout << x - 1 << " " << y << endl;
}

D. Sequence and Swaps

这道题一开始想简单了,正确思路是先判断是否已经排序好了,如果是的话直接输出0,不然把x插入每个位置进行尝试,即计算逆序,每次都进行最小值判断。

AC代码 ↓

void solve() {
int n, x;
cin >> n >> x;
vector<int> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
int ans = n + 1;
if (is_sorted(a.begin(), a.end())){//STL函数,判断是否有序
cout << 0 << endl;
return;
}
for (int i = 0; i < n; ++i) {
vector<int> b(a);
b[i] = x;
sort(b.begin(), b.end());
int cur = x, cnt = 0;
bool f = true;
for (int j = 0; j < n; ++j) {
if (a[j] != b[j]) {
++cnt;
if (cur == b[j] && b[j] < a[j])
cur = a[j];
else
f = false;
}
}
if (f)
ans = min(ans, cnt);
}
if (ans > n)
ans = -1;
cout << ans << "\n";
}

E. Four Points

直接去写的话感觉很麻烦,这里思路借鉴了rank2的大神的代码:转化为复数处理。

对标样例模拟就清楚了。

void solve() {
ll ans = 1e18;
pair<int, int> p[4];
for (int i = 0; i < 4; ++i)
cin >> p[i].first >> p[i].second;
sort(p, p + 4);
do {
vector<int> cand{0};
for (int i = 0; i < 2; ++i)
for (int j = 0; j < 2; ++j) {
cand.push_back(p[2 + j].first - p[i].first);
cand.push_back(p[2 * j + 1].second - p[2 * i].second);
} for (auto d : cand) {
if (d < 0)
continue;
ll res = 0;
int x[4], y[4];
for (int i = 0; i < 4; ++i)
tie(x[i], y[i]) = p[i]; //转化为复数处理
x[2] -= d, x[3] -= d;
y[1] -= d, y[3] -= d;
sort(x, x + 4), sort(y, y + 4);
for (int i = 0; i < 4; ++i) {
res += abs(x[i] - x[1]);
res += abs(y[i] - y[1]);
}
ans = min(res, ans);
}
} while (next_permutation(p, p + 4));
cout << ans << endl;
}

F. String and Operations

贴一下dalao代码作为学习

Code
void update(std::string& a, const std::string& b) {
if (a.empty() || a > b)
a = b;
}
void solve() {
int n, k;
std::cin >> n >> k;
std::string a, b;
std::cin >> a;
b = a;
for (int i = 0; i < n; ++i) {
if (b[i] == 'a' + k - 1)
b[i] = 'a';
else if (b[i] != 'a')
--b[i];
}
std::string dp[2][2];
dp[0][0] = a;
int cur = 0;
for (int i = 0; i < n; ++i) {
cur ^= 1;
dp[cur][0] = dp[cur][1] = "";
if (!dp[!cur][0].empty()) {
auto& s = dp[!cur][0];
update(dp[cur][0], s);
if (i > 0) {
std::swap(s[i], s[i - 1]);
update(dp[cur][0], s);
std::swap(s[i], s[i - 1]);
}
if (i + 1 < n) {
std::swap(s[i], s[i + 1]);
update(dp[cur][1], s);
std::swap(s[i], s[i + 1]);
}
s[i] = b[i];
update(dp[cur][0], s);
}
if (!dp[!cur][1].empty()) {
auto& s = dp[!cur][1];
update(dp[cur][0], s);
if (i > 1) {
std::swap(s[i - 1], s[i - 2]);
update(dp[cur][0], s);
std::swap(s[i - 1], s[i - 2]);
}
s[i - 1] = b[i];
update(dp[cur][0], s);
}
}
std::cout << dp[cur][0] << "\n";
}

G. Forbidden Value

最后一道题似乎是线段树 + DP ? 看完题没啥思路。。。(老菜鸡了)

Educational Codeforces Round 99 (Rated for Div. 2) (A ~ F)个人题解的更多相关文章

  1. Educational Codeforces Round 92 (Rated for Div. 2) B、C题解

    TAT 第一场codeforces B. Array Walk #暴力 #贪心 题目链接 题意 有\(a1, a2, ..., an\) 个格子(每个格子有各自分数),最初为1号格(初始分数为\(a1 ...

  2. Educational Codeforces Round 61 (Rated for Div. 2) D,F题解

    D. Stressful Training 题目链接:https://codeforces.com/contest/1132/problem/D 题意: 有n台电脑,每台电脑都有初始电量ai,也有一个 ...

  3. Educational Codeforces Round 76 (Rated for Div. 2)E(dp||贪心||题解写法)

    题:https://codeforces.com/contest/1257/problem/E 题意:给定3个数组,可行操作:每个数都可以跳到另外俩个数组中去,实行多步操作后使三个数组拼接起来形成升序 ...

  4. 【Educational Codeforces Round 38 (Rated for Div. 2)】 Problem A-D 题解

    [比赛链接] 点击打开链接 [题解] Problem A Word Correction[字符串] 不用多说了吧,字符串的基本操作 Problem B  Run for your prize[贪心] ...

  5. Educational Codeforces Round 96 (Rated for Div. 2) E. String Reversal 题解(思维+逆序对)

    题目链接 题目大意 给你一个长度为n的字符串,可以交换相邻两个元素,使得这个字符串翻转,求最少多少种次数改变 题目思路 如果要求数组排序所需要的冒泡次数,那其实就是逆序对 这个也差不多,但是如果是相同 ...

  6. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  7. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  8. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  9. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  10. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

随机推荐

  1. 如何使用JavaScript 将数据网格绑定到 GraphQL 服务

    前言 作为一名前端开发人员,GraphQL对于我们来说是令人难以置信的好用.它可以用来简化数据访问,这让我们的工作变得更加容易. 什么是 GraphQL?它是一个抽象层,位于任意数量的数据源之上,并为 ...

  2. 【死亡小学期第二章:没头脑和不高兴】数据库jdbc系统

    自己做一个JDBC的数据库系统,因为这个一直做嘛,所以很简单啦,并没有想提高技术拔拔高啥的,就想做一个简单的,然后自己感兴趣的内容.让自己快乐快乐那才叫做意义~~~~~~~kkkk 学到的东西: 展示 ...

  3. winform中也可以这样做数据展示✨

    1.前言 在做winform开发的过程中,经常需要做数据展示的功能,之前一直使用的是gridcontrol控件,今天想通过一个示例,跟大家介绍一下如何在winform blazor hybrid中使用 ...

  4. chrome浏览器出现《您的连接不是私密链接》

    问题现象 键盘切换到英文输入 点击页面,就页面中间随意点一下即可 不是输入框!不是输入框!不是输入框! 不是找啦!不是找啦!不是找啦! 在chrome该页面上,直接键盘敲入这11个字符:thisisu ...

  5. Tarjan 学习笔记

    萌新刚学Tarjan,啥也不会,肯定一堆错,请大佬指正谢谢 前置 强连通 强连通: 在不是强连通图的有向图\(G\)内,其顶点\(u\),\(v\)两个方向上都存在有向路径,则\(u\)和\(v\)强 ...

  6. Java并发(二十一)----wait notify介绍

    1.小故事 - 为什么需要 wait 由于条件不满足(没烟干不了活啊,等小M把烟送过来),小南不能继续进行计算 但小南如果一直占用着锁,其它人就得一直阻塞,效率太低 于是老王单开了一间休息室(调用 w ...

  7. 如何将3D模型导入可视化大屏系统中,并实现可交互的数字孪生大屏效果?

    首先我们需要准备一款数字孪生软件,本文中使用的是山海鲸可视化数字孪生软件,这是一款免费的零代码数字孪生大屏开发平台软件. 下载完成后打开山海鲸可视化,点击新建来创建一个大屏项目. 我们可以根据自己的需 ...

  8. git报错解决,warning: could not find UI helper 'git-credential-manager-ui'

    在克隆远程代码时,可能遇到这样的报错 warning: could not find UI helper 'git-credential-manager-ui' 这样的报错经常会在我们换了一台电脑或者 ...

  9. 面试官:说说JVM内存整体结构?

    Java JVM内存结构的面试常问知识 说说JVM内存整体的结构?线程私有还是共享的? JVM 整体架构,中间部分就是 Java 虚拟机定义的各种运行时数据区域. Java 虚拟机定义了若干种程序运行 ...

  10. 如何用python脚本制作生成CANdbc

    最近在工作中,有同事拿了一个excel的dbc表格,在用官方的dbc工具一个一个创建信号,大概看了一下共累计20多个节点,300多个信号,居然在手动处理,顿感无语.. 于是在网络上搜相关的dbc 通过 ...