当前位置:网站首页>Code forces round # 784 (DIV. 4) solution (First AK CF (XD)
Code forces round # 784 (DIV. 4) solution (First AK CF (XD)
2022-04-23 03:23:00 【Cofdoria】
Bien queDiv.4,Mais pour la première fois,AK,C'est un peu excitant.
A. Division?
Simulation
#include <bits/stdc++.h>
using namespace std;
string f(int n) {
if (n <= 1399) return "Division 4";
if (n <= 1599) return "Division 3";
if (n <= 1899) return "Division 2";
return "Division 1";
}
void solve() {
int n;
cin >> n;
cout << f(n) << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) solve();
return 0;
}
B. Triple
ansInitialiser comme-1,mapStatistiques
#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
void solve() {
mp.clear();
int n;
cin >> n;
int ans = -1;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
++mp[a];
if (mp[a] >= 3) ans = a;
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) solve();
return 0;
}
C. Odd/Even Increments
Est - ce que les chiffres impairs statistiques sont tous impairs ou même , Il en va de même pour les chiffres pair , En cas d'incohérence de parité NO
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int oo = 0, jj = 0;
for (int i = 0; i < n; i++) {
if ((i & 1) && (a[i] & 1)) jj++;
if (!(i & 1) && !(a[i] & 1)) ++oo;
}
if ((jj == 0 || jj == n / 2) && (oo == 0 || oo == n / 2 + (n & 1)))
cout << "YES\n";
else
cout << "NO\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) solve();
return 0;
}
D. Colorful Stamp
Appuyez.W
Segmentation, Si chaque paragraphe n'apparaît que B
Ou juste apparaître R
,EtNO
#include <bits/stdc++.h>
using namespace std;
string s;
void solve() {
int n;
cin >> n;
cin >> s;
int r = 0, b = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'R') ++r;
if (s[i] == 'B') ++b;
if (s[i] == 'W' || i == n - 1) {
if ((r > 0 && !b) || (b > 0 && !r)) {
cout << "NO\n";
return;
}
r = 0, b = 0;
}
}
cout << "YES\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) solve();
return 0;
}
E. 2-Letter Strings
Au début, j'ai pensé que c'était tordu , Je pensais que l'arbre du Dictionnaire
Ouvre.map Enregistrer le premier caractère comme a-z Nombre de chaînes de , Encore une fois map Enregistrer le deuxième caractère comme a-z Nombre de chaînes de , Et enfin map Enregistrer le nombre d'occurrences de chaque chaîne , Traverser chaque chaîne , Le nombre de chaînes qui peuvent être jumelées avec la chaîne actuelle est ( Le premier caractère est le même que la chaîne courante, mais le second est différent Plus Le deuxième caractère est le même que la chaîne courante, mais le premier caractère est différent )Monte. Le nombre de ces chaînes ,Devant.map Informations stockées pour calculer , Mais ces statistiques , Chaque paire de chaînes compte 2Une fois,Enfinans/2C'est tout.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
// ll trie[1000005][31];
map<char, ll> mp1, mp2;
map<string, ll> mp;
// ll cnt;
// char s[5];
string s;
void solve() {
mp.clear();
mp1.clear();
mp2.clear();
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
++mp1[s[0]];
++mp2[s[1]];
++mp[s];
// insert(s, 2);
}
ll ans = 0;
for (auto v : mp) {
ans += (mp1[v.first[0]] - v.second) * v.second;
ans += (mp2[v.first[1]] - v.second) * v.second;
}
ans /= 2;
cout << ans << '\n';
// for(int i=0;i<)
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) solve();
return 0;
}
F. Eating Candies
Les deux pointeurs avant et arrière vont au milieu , Mettre à jour les réponses lorsque vous mangez autant de bonbons des deux côtés , La priorité est de marcher et de manger moins , Quand on mange autant , La priorité est donnée à beaucoup de
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve() {
int n;
cin >> n;
vector<ll> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int l = 0, r = n - 1;
ll lw = a[0], rw = a[n - 1];
ll ans = 0;
while (1) {
if (l == r) break;
if (lw == rw) ans = l - 0 + 1 + n - r;
if (l == r - 1) break;
if (lw > rw) {
--r;
rw += a[r];
} else if (rw > lw) {
++l;
lw += a[l];
} else {
if (a[l + 1] > a[r - 1]) {
++l;
lw += a[l];
} else {
--r;
rw += a[r];
}
}
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) solve();
return 0;
}
G. Fall Down
Cherchez des pierres du bas de chaque colonne , Il l'a fait tomber là où il ne pouvait pas
#include <bits/stdc++.h>
using namespace std;
char s[55][55];
int n, m;
void d(int x, int y) {
for (int i = x + 1; i < n; i++) {
if (s[i][y] == '.') {
s[i][y] = '*';
s[i - 1][y] = '.';
} else
break;
}
}
void solve() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> s[i];
// cout << s[i] << '\n';
}
for (int i = 0; i < m; i++) {
for (int j = n - 1; j >= 0; j--) {
if (s[j][i] == '*') {
d(j, i);
}
}
}
for (int i = 0; i < n; i++) {
cout << s[i] << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) solve();
return 0;
}
H. Maximal AND
Statistiquesn Nombre de fois par occurrence , De la cupidité 2 30 2^{30} 230Allez. 2 0 2^0 20Satisfaire successivement,SatisfactioniBits plus 2 i 2^i 2iBesoin n − c o u n t i n-count_i n−countiPas, c o u n t i count_i countiPourn Plusieurs 2 i 2^i 2i Le nombre d'occurrences de cet homme
#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
void solve() {
mp.clear();
int n, k;
cin >> n >> k;
for (int i = 0, a; i < n; i++) {
cin >> a;
int idx = 0;
while (a) {
if (a & 1) ++mp[idx];
++idx;
a >>= 1;
}
}
int ans = 0;
for (int i = 30, t = 1 << 30; i >= 0; i--, t >>= 1) {
int q = n - mp[i];
if (k >= q) {
k -= q;
ans += t;
}
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) solve();
return 0;
}
版权声明
本文为[Cofdoria]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230322363852.html
边栏推荐
- Chapter 9 of C language programming (fifth edition of Tan Haoqiang) analysis and answer of exercises for users to establish their own data types
- MySQL keyword group_ Concat, combined connection query
- 2022 团体程序设计天梯赛 模拟赛 L2-4 哲哲打游戏 (25 分)
- The query type of MySQL is very inefficient.
- Problem B: small challenge
- Data mining series (3)_ Data mining plug-in for Excel_ Estimation analysis
- 《C语言程序设计》(谭浩强第五版) 第7章 用函数实现模块化程序设计 习题解析与答案
- Visual programming - Experiment 1
- socket编程 send()与 recv()函数详解
- Five tips for cross-border e-commerce in 2022
猜你喜欢
General testing technology [1] classification of testing
[Mysql] LEFT函数 | RIGHT函数
JS inheritance
2022g2 boiler stoker examination question bank and online simulation examination
Use of ADB command [1]
Seminar playback video: how to improve Jenkins' ability to become a real Devops platform
[MySQL] left Function | Right Function
可以接收多種數據類型參數——可變參數
xutils3修改了我提报的一个bug,开心
Top ten project management software similar to JIRA
随机推荐
MySQL installation pit
The query type of MySQL is very inefficient.
[untitled]
When migrating tslib_ setup: No such file or directory、ts_ open: No such file or director
Peut recevoir plusieurs paramètres de type de données - paramètres variables
Ide-idea-problem
全新的ORM框架——BeetlSQL介绍
After the mobile phone is connected to the computer, how can QT's QDIR read the mobile phone file path
Batch download of files ---- compressed and then downloaded
Fundamentals of software testing and development
Chapter 9 of C language programming (fifth edition of Tan Haoqiang) analysis and answer of exercises for users to establish their own data types
Téléchargement en vrac de fichiers - téléchargement après compression
MySQL索引详解【B+Tree索引、哈希索引、全文索引、覆盖索引】
C-11 problem h: treasure chest 2
2022 Shandong Province safety officer C certificate work certificate question bank and online simulation examination
js递归树结构计算每个节点的叶子节点的数量并且输出
"Visual programming" test paper
Iotos IOT middle platform is connected to the access control system of isecure center
Idea view history [file history and project history]
移植tslib时ts_setup: No such file or directory、ts_open: No such file or director