当前位置:网站首页>Codeforces Round #753 (Div. 3)
Codeforces Round #753 (Div. 3)
2022-07-06 09:14:00 【%xiao Q】
A. Linear Keyboard
大水题,暴力就行
参考代码:
#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
打表找规律,发现偶数的规律是:- + + -
奇数的规律是:+ - - +
在分类讨论,在取余求答案即可
参考代码:
#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
一道排序题,先排序,在直接安题意模拟即可
参考代码:
#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
感觉这题有点难想到,但想到的话,是非常简单的,哎,思维还是不过关呀,
前一部分,用可以进行减1的数字去得到,并按大小依次对应
后一部分,用可以进行加1的数字去得到,并按大小依次对应
然后枚举并判断对应的数字是否可行即可。
参考代码:
#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;
}
边栏推荐
- [recommended by bloggers] C # generate a good-looking QR code (with source code)
- Introduction and use of automatic machine learning framework (flaml, H2O)
- Did you forget to register or load this tag 报错解决方法
- Database advanced learning notes -- SQL statement
- Learning question 1:127.0.0.1 refused our visit
- 數據庫高級學習筆記--SQL語句
- QT creator runs the Valgrind tool on external applications
- MySQL完全卸载(Windows、Mac、Linux)
- QT creator test
- Introduction to the easy copy module
猜你喜欢
02 staff information management after the actual project
Introduction and use of automatic machine learning framework (flaml, H2O)
[recommended by bloggers] asp Net WebService background data API JSON (with source code)
windows下同时安装mysql5.5和mysql8.0
Knowledge Q & A based on Apache Jena
Install mongdb tutorial and redis tutorial under Windows
Solve the problem of installing failed building wheel for pilot
neo4j安装教程
机器学习笔记-Week02-卷积神经网络
解决安装Failed building wheel for pillow
随机推荐
SSM整合笔记通俗易懂版
數據庫高級學習筆記--SQL語句
TCP/IP协议(UDP)
【博主推荐】C#MVC列表实现增删改查导入导出曲线功能(附源码)
Copie maître - esclave MySQL, séparation lecture - écriture
Leetcode 461 Hamming distance
Dotnet replaces asp Net core's underlying communication is the IPC Library of named pipes
Basic use of redis
Why is MySQL still slow to query when indexing is used?
Introduction to the easy copy module
Unable to call numpy in pycharm, with an error modulenotfounderror: no module named 'numpy‘
MySQL主从复制、读写分离
解决:log4j:WARN Please initialize the log4j system properly.
QT creator shape
[number theory] divisor
error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_s instead
Asp access Shaoxing tourism graduation design website
Tcp/ip protocol (UDP)
【博主推荐】C#生成好看的二维码(附源码)
Invalid default value for 'create appears when importing SQL_ Time 'error reporting solution