Codeforces Round #624 (Div. 3) (A~D,CD Good)
比赛链接: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)的更多相关文章
- Codeforces Round #624 (Div. 3)(题解)
Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...
- 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 ...
- Codeforces Round #624 (Div. 3) F. Moving Points 题解
第一次写博客 ,请多指教! 翻了翻前面的题解发现都是用树状数组来做,这里更新一个 线段树+离散化的做法: 其实这道题是没有必要用线段树的,树状数组就能够解决.但是个人感觉把线段树用熟了会比树状数组更有 ...
- 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 ...
- Codeforces Round #249 (Div. 2) C题,模拟画图 ----未解决!
http://codeforces.com/contest/435/problem/C
- 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 ...
- Codeforces Round #263 (Div. 2)C(贪心,联想到huffman算法)
数学家伯利亚在<怎样解题>里说过的解题步骤第二步就是迅速想到与该题有关的原型题.(积累的重要性!) 对于这道题,可以发现其实和huffman算法的思想很相似(可能出题人就是照着改编的).当 ...
- 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 ...
- Codeforces Round #375 (Div. 2)【A,B【模拟】,D【DFS】】
PS_B:阿洗吧!B题卧槽数组开了250... PS_D:D题主要挂在了50*50口算得了250,数组开小,然后一开始还错了.= =哎,以后对于数据范围还是注意一点: 卧槽,这场可真二百五了... A ...
- Codeforces Round #374 (Div. 2)【A,B,C】
= =C题这种DP打的少吧,记得以前最短路分层图打过这样子的,然后比赛前半个小时才恍然大雾...然后瞎几把还打错了,还好A,B手速快..上分了: A题: 计算B的连续个数的组数,每组的连续个数: 水题 ...
随机推荐
- C语言二进制转换成八,十,十六进制
代码目前只支持整数转换,小数转换后续更新呀 #include <stdio.h> #include <math.h> void B_O(int n); void B_H(int ...
- 在Ubuntu机器上使用war包安装Jenkins
因为一些需求需要迁移之前使用的Jenkins,原来是按照官方文档使用apt方式安装的,这次搬迁后的机器由于默认不通外网(可以通过代理走外网),因此趁此机会,尝试改用war包方式安装 环境目标 系统Ub ...
- 通过.NET Core+Vue3 实现SignalR即时通讯功能
.NET Core 和 Vue3 结合使用 SignalR 可以实现强大的实时通讯功能,允许实时双向通信.在这个示例中,我们将详细说明如何创建一个简单的聊天应用程序,演示如何使用 .NET Core ...
- 安卓端出现https请求失败的一次问题排查
背景 某天早上,正在一个会议时,突然好几个同事被叫出去了:后面才知道,是有业务同事反馈到领导那里,我们app里面某个功能异常. 具体是这样,我们安卓版本的app是禁止截屏的(应该是app里做了拦截), ...
- 重写Nacos服务发现逻辑动态修改远程服务IP地址
背景 还是先说下做这个的背景,开发环境上了K8S,所有的微服务都注册在K8S内的Nacos,注册地址为K8S内部虚拟IP,K8S内的服务之间相互调用没有问题,但是本机开发联调调用其他微服务就访问不到. ...
- 解决This application failed to start because cannot find or load the qt platform plugin 'xcb'
问题描述: 在使用linux系统训练自己的数据集合时,出现了上述问题,首先第一个想法就是先Google,但是在看了一些国内外的文章后依然没有将问题解决 问题原因: 这是由于这几天我在安装cuda.cu ...
- 整合SpringBoot + Dubbo + Nacos 出现 Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass
版本 SpringBoot:2.7.3 Dubbo:3.0.4 Nacos:2.0.3 异常信息如下 Unable to make protected final java.lang.Class ja ...
- CodeForces - 415B Mashmokh and Tokens
Bimokh is Mashmokh's boss. For the following n days he decided to pay to his workers in a new way. A ...
- 如何使用 Helm 在 K8s 上集成 Prometheus 和 Grafana|Part 1
本系列将分成三个部分,您将学习如何使用 Helm 在 Kubernetes 上集成 Prometheus 和 Grafana,以及如何在 Grafana 上创建一个简单的控制面板.Prometheus ...
- Android联系人增删改查
1:申请权限 <uses-permission android:name="android.permission.READ_CONTACTS"/> <uses-p ...