当前位置:网站首页>【Codeforces Round #806 (Div. 4)(A~F)】
【Codeforces Round #806 (Div. 4)(A~F)】
2022-07-28 02:29:00 【浪漫主义狗】
更好的阅读体验 \color{red}{更好的阅读体验} 更好的阅读体验
文章目录
A. YES or YES?
题目大意
- 判断是否是
yes顺序的不区分大小写的字符串 - 是则输出
YES,否则输出NO
思想
- 读入暴力判断
代码
#include <bits/stdc++.h>
using namespace std;
void solve(){
string s;
cin >> s;
bool flag = 1;
if(s[0] != 'y' && s[0] != 'Y') flag = 0;
if(s[1] != 'e' && s[1] != 'E') flag = 0;
if(s[2] != 's' && s[2] != 'S') flag = 0;
if(s.size() == 3 && flag) cout << "YES" << endl;
else cout << "NO" << endl;
}
int main(){
int _;
cin >> _;
while(_--){
solve();
}
return 0;
}
B. ICPC Balloons
题目大意
- 共 A ∼ Z A \sim Z A∼Z道题,第一次出现送出两个气球,后续出现送出一个气球
- 求比赛共送出多少气球
思想
vis[i]标记是否出现过- 未出现的送出两个,出现过送出一个
- 遍历字符串求和
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
typedef long long LL;
bool vis[N];
void solve(){
memset(vis,0,sizeof vis);
int n;
cin >> n;
LL cnt = 0;
while(n--){
char a;
cin >> a;
if(!vis[a]){
cnt += 2;
vis[a] = 1;
}
else cnt ++;
}
cout << cnt << endl;
}
int main(){
int _;
cin >> _;
while(_--){
solve();
}
return 0;
}
C. Cypher
题目大意
- 每个密码锁有 n n n个轮子,轮子上有 0 ∼ 9 0\sim 9 0∼9
- 给出最终位置显示的数字 a i a_i ai,和第 i i i个位置的 b i b_i bi次操作
- 求原始的数字
思想
- 模拟
ans[i]存储第 i i i位的最终数字,用flag存储操作的偏移量- 若为
U则flag --,反之flag ++ - 对于
ans[i],加上其偏移量并取正整数模,即ans[i] = ( ans[i] + flag % 10 + 10 ) % 10即为原始数字
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n;
int ans[N];
void solve(){
cin >> n;
for(int i = 1; i <= n; i ++) cin >> ans[i];
for(int i = 1; i <= n; i ++){
int m;
cin >> m;
int flag = 0;
while(m--){
char op;
cin >> op;
if(op == 'D') flag ++;
else flag --;
}
ans[i] = (ans[i] + flag % 10 + 10) % 10;
}
for(int i = 1; i <= n; i ++) cout << ans[i] << " ";
cout << endl;
}
int main(){
int _;
cin >> _;
while(_--){
solve();
}
return 0;
}
D. Double Strings
题目大意
- 给定 n n n个长度不超过 8 8 8的字符串 s s s
- 若对于 s i = s j + s k s_i = s_j + s_k si=sj+sk成立,则 s i s_i si标记为 1 1 1,否则标记为 0 0 0
思想
- n n n比较大,但 s i s_i si较短
- 对于 s i s_i si,每次构造两个 s i s_i si的字串 s i ′ , s i ′ ′ s_i',s_i'' si′,si′′,对字串进行查询
- 若两个字串都可以找到,则标记 s i s_i si为 1 1 1,反之为 0 0 0
- 利用
s[N]和set<string> st同时存储所有的s[i] - 遍历
s[i],第一个字串从s[0]开始,长度为1 <= j <= s[i].size() - 1,第二个字串从s[j]开始,长度为s[i].size() - j - 利用
st.count(s)查询字串s
代码
#include <bits/stdc++.h>
using namespace std;
void solve(){
int n;
cin >> n;
bool vis[n + 10];
memset(vis,0,sizeof vis);
set<string> st;
string s[n + 1];
for(int i = 0; i < n; i ++){
cin >> s[i];
st.insert(s[i]);
}
for(int i = 0; i < n; i ++){
if(s[i].size() == 1) continue;
for(int j = 1; j <= s[i].size() - 1; j ++){
string s1 = s[i].substr(0,j), s2 = s[i].substr(j,s[i].size() - j);
if(st.count(s1) == 1 && st.count(s2) == 1){
vis[i] = 1;
break;
}
}
}
for(int i = 0; i < n; i ++){
if(vis[i]) cout << 1;
else cout << 0;
}
cout << endl;
}
int main(){
int _;
cin >> _;
while(_--){
solve();
}
return 0;
}
E. Mirror Grid
题目大意
- 给定由 0 0 0和 1 1 1构成正方形数组
- 将数组向右选择90度,180度,270度
- 求如何改变原数组中的值,使得四种形态的数组里的值都一样的改变最少操作次数
思想
- 原二维数组中的一个位置
mp[i][j]旋转三次后,总共会出现在三个位置上 - 即
mp[j][n + 1 - i]、mp[n + 1 - i][n + 1 - j]、mp[n + 1 - j][i] - 统计原位置的值和这三个新位置的值变为相同的最小操作次数即可
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
char mp[N][N];
bool st[N][N];
void solve()
{
int n;
cin >> n;
memset(st, 0, sizeof st);
for (int i = 1; i <= n; i++) cin >> mp[i] + 1;
int ans = 0;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= n; j++){
if(i == j && n % 2 == 1) continue;
if(!st[i][j]){
int cnt = 0;
if(mp[i][j] == '1') cnt++;
st[i][j] = 1;
if(mp[j][n - i + 1] == '1') cnt++;
st[j][n - i + 1] = 1;
if(mp[n - i + 1][n - j + 1] == '1') cnt++;
st[n - i + 1][n - j + 1] = 1;
if(mp[n - j + 1][i] == '1') cnt++;
st[n - j + 1][i] = 1;
ans += min(cnt, 4 - cnt);
}
}
}
cout << ans << endl;
}
int main(){
int _;
cin >> _;
while(_--){
solve();
}
return 0;
}
F. Yet Another Problem About Pairs Satisfying an Inequality
题目大意
- 对于数列 a a a,找到满足 a i < i < a j < j , 1 ≤ i , j ≤ n a_i \lt i\lt a_j<j,1\le i,j\le n ai<i<aj<j,1≤i,j≤n的 i , j i,j i,j对数
思想
- 对于 a i < i < a j < j , 1 ≤ i , j ≤ n a_i \lt i\lt a_j<j,1\le i,j\le n ai<i<aj<j,1≤i,j≤n
- 一定满足
a[i] < i,将a[i] >= i的删去,不参与后续匹配 - 一定满足
i < a[j],{i,j}的对数为i之前的满足a[i] < i的数量
- 一定满足
- 枚举
j,二分查找最小满足i < a[j]的位置,总数量加上i之前的所有满足a[i] < i的数量
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 3;
int a[N];
typedef long long LL;
LL cnt;
vector<int> st;
void solve(){
int n;
cin >> n;
st.clear();
cnt = 0;
for(int i = 1; i <= n; i ++) cin >> a[i];
for(int i = 1; i <= n; i ++){
if (a[i] >= i) continue;
cnt += (lower_bound(st.begin(), st.end(), a[i]) - st.begin());
st.push_back(i);
}
cout << cnt << endl;
}
int main(){
int _;
cin >> _;
while(_--){
solve();
}
return 0;
}
边栏推荐
- C#实现弹出一个对话框的同时,后面的form不可用
- QML使用Layout布局时出现大量<Unknown File>: QML QQuickLayoutAttached: Binding loop detected for property循环绑定警告
- 随机森林与集成方法学习笔记
- @The function of valid (cascade verification) and the explanation of common constraint annotations
- els 定时器
- 【下载文件】uniapp开发小程序,下载文件并保存到本地
- JS event object 2 e.charcode character code e.keycode key code box moves up, down, left and right
- MySQL索引学习
- Web服务器
- 【stream】stream流基础知识
猜你喜欢

Thread Foundation

CNN training cycle reconstruction - hyperparametric test | pytorch series (XXVIII)

The test post changes jobs repeatedly, jumping and jumping, and then it disappears

Record of a cross domain problem

What "posture" does JD cloud have to promote industrial digitalization to climb to a "new level"?

Opengauss Developer Day 2022 sincerely invites you to visit the "database kernel SQL Engine sub forum" of Yunhe enmo

JVM 内存布局详解,图文并茂,写得太好了!

43.js -- scope chain

一次跨域问题的记录

行业洞察 | 语音识别真的超过人耳朵了吗?
随机推荐
els 键盘信息
Random forest and integration method learning notes
一次跨域问题的记录
Confusion matrix in CNN | pytorch series (XXIII)
Design and practice of unified security authentication for microservice architecture
基于OpenCV的轮廓检测(3)
[email protected] Annotation usage
style=“width: ___“ VS width=“___“
els 显示一个随机方块
[QNX Hypervisor 2.2用户手册]9.10 pass
Data center construction (III): introduction to data center architecture
Qt官方示例:Fridge Magnets Example(冰箱贴)
Day 8 of DL
意外收获史诗级分布式资源,从基础到进阶都干货满满,大佬就是强!
app 自动化 环境搭建(一)
Pytorch 相关-梯度回传
数据湖:海量日志采集引擎Flume
clientY vs pageY
My approval & signature function of conference OA project
ECCV 2022 | open source for generative knowledge distillation of classification, detection and segmentation