当前位置:网站首页>Codeforces Round #753 (Div. 3)
Codeforces Round #753 (Div. 3)
2022-07-06 11:25:00 【%xiao Q】
A. Linear Keyboard
Big water , Violence will do
Reference code :
#include <iostream>
#include <unordered_map>
#include <cmath>
using namespace std;
const int N = 50;
unordered_map<char, int> q;
int main()
{
string s1, s2;
int T;
cin >> T;
while(T--)
{
cin >> s1 >> s2;
for(int i = 0; i < s1.size(); i++)
q[s1[i]] = i + 1;
int ans = 0;
for(int i = 1; i < s2.size(); i++)
{
if(s2[i] == s2[i - 1]) continue;
ans += abs(q[s2[i]] - q[s2[i - 1]]);
}
cout << ans << endl;
}
}
B. Odd Grasshopper
Beat the watch to find the rules , It is found that the law of even numbers is :- + + -
The law of odd numbers is :+ - - +
Discuss in classification , Just take the remainder and find the answer
Reference code :
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
int main()
{
int T;
cin >> T;
while(T--)
{
LL x, t;
scanf("%lld%lld", &x, &t);
if(x % 2 == 0)
{
if(t % 4 == 1) x -= t;
else if(t % 4 == 2) x += 1;
else if(t % 4 == 3) x += t + 1;
}
else
{
if(t % 4 == 1) x += t;
else if(t % 4 == 2) x -= 1;
else if(t % 4 == 3) x -= (t + 1);
}
printf("%lld\n", x);
}
return 0;
}
C. Minimum Extraction
A sorting problem , Prioritize , In the direct safety topic meaning simulation can
Reference code :
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
int a[N];
LL s[N];
int main()
{
int T;
cin >> T;
while(T--)
{
int n;
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
LL ans = -2e9, sum = 0;
for(int i = 1; i <= n; i++)
{
ans = max(ans, a[i] - sum);
sum += (a[i] - sum);
}
cout << ans << endl;
}
return 0;
}
D. Blue-Red Permutation
I feel this question is a little difficult to think of , But when I think of it , It's very simple , Ah , Thinking is still not good ,
The former part , Use to subtract 1 Go and get , And corresponding in order of size
The latter part , Use to add 1 Go and get , And corresponding in order of size
Then enumerate and judge whether the corresponding number is feasible .
Reference code :
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
int T;
cin >> T;
while(T--)
{
int n;
cin >> n;
vector<int> a(n), b, r;
for(int i = 0; i < n; i++) cin >> a[i];
char ch;
for(int i = 0; i < n; i++)
{
cin >> ch;
if(ch == 'B') b.push_back(a[i]);
else r.push_back(a[i]);
}
sort(b.begin(), b.end());
sort(r.begin(), r.end());
bool flag = true; int t = 1;
for(auto i : b)
{
if(i < t) flag = false;
t++;
}
for(auto i : r)
{
if(i > t) flag = false;
t++;
}
if(flag) puts("YES");
else puts("NO");
}
return 0;
}
边栏推荐
- FRP intranet penetration
- vs2019 使用向导生成一个MFC应用程序
- Did you forget to register or load this tag 报错解决方法
- MySQL主從複制、讀寫分離
- AcWing 1298.曹冲养猪 题解
- Redis的基础使用
- error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_s instead
- 安装numpy问题总结
- Codeforces Round #753 (Div. 3)
- Ansible practical Series III_ Task common commands
猜你喜欢

Did you forget to register or load this tag 报错解决方法
![[recommended by bloggers] C # generate a good-looking QR code (with source code)](/img/5a/1dbafe5a28f016b815964b9b37c9f1.jpg)
[recommended by bloggers] C # generate a good-looking QR code (with source code)

error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_s instead

Django运行报错:Error loading MySQLdb module解决方法

PHP - whether the setting error displays -php xxx When PHP executes, there is no code exception prompt

Mtcnn face detection

引入了junit为什么还是用不了@Test注解

Deoldify项目问题——OMP:Error#15:Initializing libiomp5md.dll,but found libiomp5md.dll already initialized.

MySQL主从复制、读写分离

How to build a new project for keil5mdk (with super detailed drawings)
随机推荐
Redis的基础使用
What does usart1 mean
Why can't STM32 download the program
Ansible实战系列一 _ 入门
LeetCode #461 汉明距离
基于apache-jena的知识问答
Project practice - background employee information management (add, delete, modify, check, login and exit)
FRP intranet penetration
[蓝桥杯2020初赛] 平面切分
Basic use of redis
vs2019 第一个MFC应用程序
自动机器学习框架介绍与使用(flaml、h2o)
报错解决 —— io.UnsupportedOperation: can‘t do nonzero end-relative seeks
Detailed reading of stereo r-cnn paper -- Experiment: detailed explanation and result analysis
AcWing 1298.曹冲养猪 题解
Learn winpwn (2) -- GS protection from scratch
QT creator create button
使用lambda在循环中传参时,参数总为同一个值
库函数--(持续更新)
01 project demand analysis (ordering system)