比赛链接:Here

1311A. Add Odd or Subtract Even

签到题,

  • \(a > b\) 时必须做做减法,如果差值为偶数的话只需要 \(1\) 次不然做一次减法后再做一次 \(+1\) 即可
  • \(a < b\) 同理了
  • \(a = b\) 0次
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
ll a, b;
cin >> a >> b;
if (a == b) cout << "0\n";
else if (a > b) {
if ((a - b) & 1) cout << "2\n";
else cout << "1\n";
} else {
if ((a - b) & 1) cout << "1\n";
else cout << "2\n";
}
}
}

1311B. WeirdSort

题意:给出长度为 \(n\)​ 的数组以及长度为 \(m\)​ 的允许进行 \(swap(a[i],a[i + 1])\) 的下标,

问经过若干次之后是否能使得数组有序

思路:

注意到 \(n\le 100\) 那么我可以直接跑若干次循环对于 \(a[i] < a[i + 1]\) 的地方交换 (前提是允许交换),

如果最后有序了就输出 YES

const int N = 110;
int a[N], st[N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i) cin >> a[i];
memset(st, 0, sizeof(st));
for (int i = 1, x; i <= m; ++i) cin >> x, st[x] = 1;
for (int i = 0; i < n; ++i)
for (int j = 1; j < n; ++j)
if (a[j] > a[j + 1] and st[j]) swap(a[j], a[j + 1]);
bool f = 1;
for (int i = 1; i < n and f; ++i) if (a[i] > a[i + 1]) f = 0;
cout << (f ? "YES\n" : "NO\n");
}
}

1311C. Perform the Combo

题意:给一个长度为n的字符串 会犯m个错误 每次犯错误就要重新输入

问你所有字母共打了多少次?

思路

似乎很多人用前缀和写的,

我的思路是在某个位置去二分找是否有若干次在它之后会出错的次数并累计即可。

int cnt[300];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
memset(cnt, 0, sizeof(cnt));
int n, m;
string s;
cin >> n >> m >> s;
vector<int>p;
for (int i = 0, x; i < m; ++i) {
cin >> x;
p.emplace_back(x);
}
sort(p.begin(), p.end());
for (int i = 0; i < n; ++i) {
int t = p.end() - lower_bound(p.begin(), p.end(), i + 1);
cnt[s[i]] += 1 + t;
// cout << s[i] << ": " << t << "\n";
}
for (auto c = 'a'; c <= 'z'; ++c) cout << cnt[c] << " ";
cout << "\n";
}
}

1311D. Three Integers

题意:

给了\(a、b、c\) 三个数,现在你可以对任意一个数进行任意次数的 \(+1\) 和 \(-1\) 问你最少操作次数让\(b\%a=0,c\%b=0\)

思路:

那 \(a,b,c\) 改变的最大范围也就是 \([1,10000]\),直接枚举就可以,但是 \(10000^3\)​ 明显是会超时的。这里稍微优化一下。

int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
int a, b, c;
cin >> a >> b >> c;
int aa = a, bb = b, cc = c;
int cnt = INT_MAX;
for (int i = 1; i <= 11000; ++i)
for (int j = 1; i * j <= 11000; ++j)
for (int k = 1; i * j * k <= 11000; ++k) {
if (cnt > abs(i - a) + abs(i * j - b) + abs(i * j * k - c)) {
cnt = abs(i - a) + abs(i * j - b) + abs(i * j * k - c);
aa = i, bb = i * j, cc = i * j * k;
}
}
cout << cnt << "\n" << aa << " " << bb << " " << cc << "\n";
}
}

Codeforces Round #624 (Div. 3) (A~D,CD Good)的更多相关文章

  1. Codeforces Round #624 (Div. 3)(题解)

    Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...

  2. Codeforces Round #395 (Div. 2)(A.思维,B,水)

    A. Taymyr is calling you time limit per test:1 second memory limit per test:256 megabytes input:stan ...

  3. Codeforces Round #624 (Div. 3) F. Moving Points 题解

    第一次写博客 ,请多指教! 翻了翻前面的题解发现都是用树状数组来做,这里更新一个 线段树+离散化的做法: 其实这道题是没有必要用线段树的,树状数组就能够解决.但是个人感觉把线段树用熟了会比树状数组更有 ...

  4. Codeforces Round #624 (Div. 3) C. Perform the Combo(前缀和)

    You want to perform the combo on your opponent in one popular fighting game. The combo is the string ...

  5. Codeforces Round #249 (Div. 2) C题,模拟画图 ----未解决!

    http://codeforces.com/contest/435/problem/C

  6. Codeforces Round #258 (Div. 2)(A,B,C,D)

    题目链接 A. Game With Sticks time limit per test:1 secondmemory limit per test:256 megabytesinput:standa ...

  7. Codeforces Round #263 (Div. 2)C(贪心,联想到huffman算法)

    数学家伯利亚在<怎样解题>里说过的解题步骤第二步就是迅速想到与该题有关的原型题.(积累的重要性!) 对于这道题,可以发现其实和huffman算法的思想很相似(可能出题人就是照着改编的).当 ...

  8. Codeforces Round #323 (Div. 2) B 贪心,暴力

    B. Robot's Task time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  9. Codeforces Round #375 (Div. 2)【A,B【模拟】,D【DFS】】

    PS_B:阿洗吧!B题卧槽数组开了250... PS_D:D题主要挂在了50*50口算得了250,数组开小,然后一开始还错了.= =哎,以后对于数据范围还是注意一点: 卧槽,这场可真二百五了... A ...

  10. Codeforces Round #374 (Div. 2)【A,B,C】

    = =C题这种DP打的少吧,记得以前最短路分层图打过这样子的,然后比赛前半个小时才恍然大雾...然后瞎几把还打错了,还好A,B手速快..上分了: A题: 计算B的连续个数的组数,每组的连续个数: 水题 ...

随机推荐

  1. Java笔记——常用类

    一.API概述 JDK中提供的各种功能的Java类 二.Object类 概述 类层次结构的根类 所有类都直接或间接的继承自该类 Class Object是类object结构的根.每个Class都有ob ...

  2. 总结(6)--- python基础知识点小结(细全)

    ==================================================================================================== ...

  3. Python 哈希表的实现——字典

    哈喽大家好,我是咸鱼 接触过 Python 的小伙伴应该对[字典]这一数据类型都了解吧 虽然 Python 没有显式名称为"哈希表"的内置数据结构,但是字典是哈希表实现的数据结构 ...

  4. 图文剖析 big.js 四则运算源码

    big.js,一个小型.快速的用于任意精度的十进制算术的JavaScript 库. big.js 用于解决平常项目中进行算术运算时精度丢失引起的结果不准确的问题.和 big.js 类似的两个库 big ...

  5. [CF1854D] Michael and Hotel

    题目描述 Michael and Brian are stuck in a hotel with $ n $ rooms, numbered from $ 1 $ to $ n $ , and nee ...

  6. [ARC145D] Non Arithmetic Progression Set

    Problem Statement Construct a set $S$ of integers satisfying all of the conditions below. It can be ...

  7. [python]数据分析--数据清洗处理case1

    数据预处理案例1 主要涉及pandas读取csv文件,缺失值和重复值处理,分组计数,字段类型转换 ,结果写入到Excel. 根据要求对CSV数据集进行处理要求如下: 保留数据关键信息:time.lat ...

  8. 设置ElementUI的el-table组件表格内容居中

    方式一:比较麻烦 // 在每一个el-table-column中添加align='center'属性 <el-table-column prop='createTime' label='创建时间 ...

  9. 【内核】ELF 文件执行流程

    # ELF 文件分类 Linux中,ELF文件全称为:Executable and Linkable Format,主要有三种形式,分别是: 可执行文件 动态库文件(共享文件 .so) 目标文件(可重 ...

  10. 什么是 MySQL JDBC 连接池中最高效的连接检测语句?

    在回答这个问题之前,首先我们看看 MySQL 中有哪些常用的 JDBC 连接池: c3p0 DBCP Druid Tomcat JDBC Pool HikariCP 这些连接池中,c3p0 是一个老牌 ...