当前位置:网站首页>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;
}
边栏推荐
- QT creator runs the Valgrind tool on external applications
- neo4j安装教程
- 数据库高级学习笔记--SQL语句
- Ansible实战系列一 _ 入门
- Deoldify项目问题——OMP:Error#15:Initializing libiomp5md.dll,but found libiomp5md.dll already initialized.
- 连接MySQL数据库出现错误:2059 - authentication plugin ‘caching_sha2_password‘的解决方法
- L2-001 紧急救援 (25 分)
- MySQL的一些随笔记录
- When you open the browser, you will also open mango TV, Tiktok and other websites outside the home page
- Basic use of redis
猜你喜欢
Django运行报错:Error loading MySQLdb module解决方法
软件测试与质量学习笔记3--白盒测试
Vs2019 desktop app quick start
Machine learning -- census data analysis
error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_s instead
Integration test practice (1) theoretical basis
AcWing 1298. Solution to Cao Chong's pig raising problem
打开浏览器的同时会在主页外同时打开芒果TV,抖音等网站
Basic use of redis
Did you forget to register or load this tag
随机推荐
Integration test practice (1) theoretical basis
Julia 1.6 1.7 common problem solving
Learning question 1:127.0.0.1 refused our visit
安装numpy问题总结
数数字游戏
AI benchmark V5 ranking
ImportError: libmysqlclient. so. 20: Cannot open shared object file: no such file or directory solution
Did you forget to register or load this tag 报错解决方法
C语言读取BMP文件
记某公司面试算法题:查找一个有序数组某个数字出现的次数
Install mysql5.5 and mysql8.0 under windows at the same time
Django运行报错:Error loading MySQLdb module解决方法
Software testing and quality learning notes 3 -- white box testing
MySQL主从复制、读写分离
Heating data in data lake?
LeetCode #461 汉明距离
Data dictionary in C #
數據庫高級學習筆記--SQL語句
Machine learning -- census data analysis
Ansible实战系列二 _ Playbook入门