当前位置:网站首页>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;
}
边栏推荐
- Julia 1.6 1.7 common problem solving
- Detailed reading of stereo r-cnn paper -- Experiment: detailed explanation and result analysis
- vs2019 使用向导生成一个MFC应用程序
- Kept VRRP script, preemptive delay, VIP unicast details
- [蓝桥杯2020初赛] 平面切分
- 打开浏览器的同时会在主页外同时打开芒果TV,抖音等网站
- [蓝桥杯2017初赛]方格分割
- Data dictionary in C #
- ES6 let 和 const 命令
- MySQL与c语言连接(vs2019版)
猜你喜欢
QT creator runs the Valgrind tool on external applications
Kept VRRP script, preemptive delay, VIP unicast details
Why can't I use the @test annotation after introducing JUnit
Detailed reading of stereo r-cnn paper -- Experiment: detailed explanation and result analysis
QT creator shape
Vs2019 desktop app quick start
Basic use of redis
MTCNN人脸检测
Copie maître - esclave MySQL, séparation lecture - écriture
AcWing 1298. Solution to Cao Chong's pig raising problem
随机推荐
Ansible实战系列三 _ task常用命令
[蓝桥杯2021初赛] 砝码称重
Classes in C #
UDS learning notes on fault codes (0x19 and 0x14 services)
MySQL主从复制、读写分离
MTCNN人脸检测
使用lambda在循环中传参时,参数总为同一个值
Introduction and use of automatic machine learning framework (flaml, H2O)
AcWing 1294.樱花 题解
Summary of numpy installation problems
Learning question 1:127.0.0.1 refused our visit
MySQL与c语言连接(vs2019版)
Julia 1.6 1.7 common problem solving
图片上色项目 —— Deoldify
AcWing 1298.曹冲养猪 题解
Solve the problem of installing failed building wheel for pilot
L2-004 这是二叉搜索树吗? (25 分)
02 staff information management after the actual project
Did you forget to register or load this tag
Knowledge Q & A based on Apache Jena