当前位置:网站首页>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;
}
边栏推荐
- Redis的基础使用
- 虚拟机Ping通主机,主机Ping不通虚拟机
- 01 project demand analysis (ordering system)
- AcWing 179. Factorial decomposition problem solution
- Introduction to the easy copy module
- MySQL主從複制、讀寫分離
- Generate PDM file from Navicat export table
- MySQL主从复制、读写分离
- Postman Interface Association
- When you open the browser, you will also open mango TV, Tiktok and other websites outside the home page
猜你喜欢
Asp access Shaoxing tourism graduation design website
[recommended by bloggers] C WinForm regularly sends email (with source code)
Install mysql5.5 and mysql8.0 under windows at the same time
Windows cannot start the MySQL service (located on the local computer) error 1067 the process terminated unexpectedly
error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_s instead
Swagger, Yapi interface management service_ SE
QT creator test
[recommended by bloggers] C MVC list realizes the function of adding, deleting, modifying, checking, importing and exporting curves (with source code)
解决安装Failed building wheel for pillow
[C language foundation] 04 judgment and circulation
随机推荐
Test objects involved in safety test
Record a problem of raspberry pie DNS resolution failure
Remember the interview algorithm of a company: find the number of times a number appears in an ordered array
记一次某公司面试题:合并有序数组
打开浏览器的同时会在主页外同时打开芒果TV,抖音等网站
La table d'exportation Navicat génère un fichier PDM
Windows下安装MongDB教程、Redis教程
Ansible实战系列三 _ task常用命令
Install MySQL for Ubuntu 20.04
Neo4j installation tutorial
Asp access Shaoxing tourism graduation design website
[C language foundation] 04 judgment and circulation
[recommended by bloggers] C # generate a good-looking QR code (with source code)
AI benchmark V5 ranking
Knowledge Q & A based on Apache Jena
QT creator design user interface
MySQL主從複制、讀寫分離
Remember a company interview question: merge ordered arrays
What does usart1 mean
Deoldify项目问题——OMP:Error#15:Initializing libiomp5md.dll,but found libiomp5md.dll already initialized.