当前位置:网站首页>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;
}
边栏推荐
- 数据库高级学习笔记--SQL语句
- Introduction to the easy copy module
- Database advanced learning notes -- SQL statement
- Error connecting to MySQL database: 2059 - authentication plugin 'caching_ sha2_ The solution of 'password'
- Redis的基础使用
- Swagger, Yapi interface management service_ SE
- Introduction and use of automatic machine learning framework (flaml, H2O)
- AcWing 179. Factorial decomposition problem solution
- MySQL与c语言连接(vs2019版)
- Deoldify project problem - omp:error 15:initializing libiomp5md dll,but found libiomp5md. dll already initialized.
猜你喜欢
Cookie setting three-day secret free login (run tutorial)
Pytorch基础
Request object and response object analysis
Mtcnn face detection
[download app for free]ineukernel OCR image data recognition and acquisition principle and product application
Basic use of redis
AcWing 1298. Solution to Cao Chong's pig raising problem
Redis的基础使用
How to configure flymcu (STM32 serial port download software) is shown in super detail
Asp access Shaoxing tourism graduation design website
随机推荐
Pytorch基础
Install MySQL for Ubuntu 20.04
图片上色项目 —— Deoldify
人脸识别 face_recognition
Machine learning notes week02 convolutional neural network
AcWing 1294.樱花 题解
Introduction and use of automatic machine learning framework (flaml, H2O)
LeetCode #461 汉明距离
Django running error: error loading mysqldb module solution
Introduction to the easy copy module
Library function -- (continuous update)
Case analysis of data inconsistency caused by Pt OSC table change
Copie maître - esclave MySQL, séparation lecture - écriture
[number theory] divisor
When you open the browser, you will also open mango TV, Tiktok and other websites outside the home page
AI benchmark V5 ranking
Detailed reading of stereo r-cnn paper -- Experiment: detailed explanation and result analysis
PyCharm中无法调用numpy,报错ModuleNotFoundError: No module named ‘numpy‘
Asp access Shaoxing tourism graduation design website
01 project demand analysis (ordering system)