当前位置:网站首页>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;
}
边栏推荐
- Pytorch基础
- What does BSP mean
- 虚拟机Ping通主机,主机Ping不通虚拟机
- 连接MySQL数据库出现错误:2059 - authentication plugin ‘caching_sha2_password‘的解决方法
- 02-项目实战之后台员工信息管理
- The virtual machine Ping is connected to the host, and the host Ping is not connected to the virtual machine
- SSM integrated notes easy to understand version
- A brief introduction to the microservice technology stack, the introduction and use of Eureka and ribbon
- 记一次某公司面试题:合并有序数组
- [download app for free]ineukernel OCR image data recognition and acquisition principle and product application
猜你喜欢

Deoldify项目问题——OMP:Error#15:Initializing libiomp5md.dll,but found libiomp5md.dll already initialized.

解决安装Failed building wheel for pillow

Neo4j installation tutorial

QT creator specify editor settings

自动机器学习框架介绍与使用(flaml、h2o)

一键提取pdf中的表格

error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_s instead

csdn-Markdown编辑器

Some problems in the development of unity3d upgraded 2020 VR

Swagger、Yapi接口管理服务_SE
随机推荐
Error reporting solution - io UnsupportedOperation: can‘t do nonzero end-relative seeks
MySQL other hosts cannot connect to the local database
Unable to call numpy in pycharm, with an error modulenotfounderror: no module named 'numpy‘
csdn-Markdown编辑器
Solve the problem of installing failed building wheel for pilot
虚拟机Ping通主机,主机Ping不通虚拟机
QT creator uses Valgrind code analysis tool
记某公司面试算法题:查找一个有序数组某个数字出现的次数
In the era of DFI dividends, can TGP become a new benchmark for future DFI?
Pytorch基础
Copie maître - esclave MySQL, séparation lecture - écriture
AcWing 1298.曹冲养猪 题解
Ubuntu 20.04 安装 MySQL
QT creator create button
Solution: log4j:warn please initialize the log4j system properly
The virtual machine Ping is connected to the host, and the host Ping is not connected to the virtual machine
MySQL主从复制、读写分离
Ansible实战系列二 _ Playbook入门
MySQL完全卸载(Windows、Mac、Linux)
[ahoi2009]chess Chinese chess - combination number optimization shape pressure DP