当前位置:网站首页>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;
}
边栏推荐
- Integration test practice (1) theoretical basis
- double转int精度丢失问题
- [蓝桥杯2021初赛] 砝码称重
- Face recognition_ recognition
- error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_s instead
- QT creator runs the Valgrind tool on external applications
- [ahoi2009]chess Chinese chess - combination number optimization shape pressure DP
- 软件测试与质量学习笔记3--白盒测试
- AcWing 179. Factorial decomposition problem solution
- neo4j安装教程
猜你喜欢

Did you forget to register or load this tag

Unable to call numpy in pycharm, with an error modulenotfounderror: no module named 'numpy‘

neo4j安装教程

Did you forget to register or load this tag 报错解决方法

Mtcnn face detection

Image recognition - pyteseract TesseractNotFoundError: tesseract is not installed or it‘s not in your path

Redis的基础使用

MySQL master-slave replication, read-write separation

Solution: log4j:warn please initialize the log4j system properly

QT creator specify editor settings
随机推荐
Aborted connection 1055898 to db:
One click extraction of tables in PDF
Cookie setting three-day secret free login (run tutorial)
What does usart1 mean
MySQL与c语言连接(vs2019版)
连接MySQL数据库出现错误:2059 - authentication plugin ‘caching_sha2_password‘的解决方法
What does BSP mean
TCP/IP协议(UDP)
MySQL的一些随笔记录
Learn winpwn (2) -- GS protection from scratch
Introduction to the easy copy module
L2-004 这是二叉搜索树吗? (25 分)
L2-006 树的遍历 (25 分)
AcWing 1298.曹冲养猪 题解
Pytorch基础
天梯赛练习集题解LV1(all)
Vs2019 desktop app quick start
Learning question 1:127.0.0.1 refused our visit
Integration test practice (1) theoretical basis
[download app for free]ineukernel OCR image data recognition and acquisition principle and product application