当前位置:网站首页>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;
}
边栏推荐
- Project practice - background employee information management (add, delete, modify, check, login and exit)
- Error reporting solution - io UnsupportedOperation: can‘t do nonzero end-relative seeks
- Attention apply personal understanding to images
- Error connecting to MySQL database: 2059 - authentication plugin 'caching_ sha2_ The solution of 'password'
- 记某公司面试算法题:查找一个有序数组某个数字出现的次数
- Redis的基础使用
- The virtual machine Ping is connected to the host, and the host Ping is not connected to the virtual machine
- neo4j安装教程
- Ansible实战系列三 _ task常用命令
- UDS learning notes on fault codes (0x19 and 0x14 services)
猜你喜欢
[recommended by bloggers] C MVC list realizes the function of adding, deleting, modifying, checking, importing and exporting curves (with source code)
Unable to call numpy in pycharm, with an error modulenotfounderror: no module named 'numpy‘
QT creator test
Invalid global search in idea/pychar, etc. (win10)
Generate PDM file from Navicat export table
[recommended by bloggers] C # generate a good-looking QR code (with source code)
AI benchmark V5 ranking
Esp8266 at+cipstart= "", "", 8080 error closed ultimate solution
LeetCode #461 汉明距离
基于apache-jena的知识问答
随机推荐
AcWing 179.阶乘分解 题解
Antlr4 uses keywords as identifiers
[recommended by bloggers] C WinForm regularly sends email (with source code)
Database advanced learning notes -- SQL statement
Picture coloring project - deoldify
Windows cannot start the MySQL service (located on the local computer) error 1067 the process terminated unexpectedly
AcWing 1298.曹冲养猪 题解
JDBC principle
Request object and response object analysis
Why can't I use the @test annotation after introducing JUnit
Solve the problem of installing failed building wheel for pilot
MySQL other hosts cannot connect to the local database
QT creator custom build process
error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_s instead
[ahoi2009]chess Chinese chess - combination number optimization shape pressure DP
Some notes of MySQL
打开浏览器的同时会在主页外同时打开芒果TV,抖音等网站
Remember a company interview question: merge ordered arrays
QT creator runs the Valgrind tool on external applications
Install mysql5.5 and mysql8.0 under windows at the same time