当前位置:网站首页>Codeforces Round #784 (Div. 4)
Codeforces Round #784 (Div. 4)
2022-04-23 19:07:00 【_ Cauchy】
List of articles
A Division?
The question
: Segmented output r a t i n g {rating} rating Level corresponding to value
void solve() {
int n; cin >> n;
int x = -1;
if(n >= 1900) x = 1;
else if(n >= 1600) x = 2;
else if(n >= 1400) x = 3;
else if(n <= 1399) x = 4;
cout << "Division " << x << endl;
}
B Triple
The question
: A number in a given array appears > = {>=} >= 3 Output the number once , Otherwise output − 1 {-1} −1
map<int, int> s;
void solve() {
s.clear();
int n; cin >> n;
int o = 0;
int res = 0;
for (int i= 0; i < n; i++) {
int x; cin >> x;
s[x] ++;
if(s[x] >= 3) o = 1, res = x;
}
if(o) cout << res << endl;
else cout << -1 << endl;
}
C Odd/Even Increments
The question
: Or for all odd bits , Or operate on all even bits once , Ask whether the parity performance of the last array is consistent .
operation : + 1 or + 0 { +1 or +0 } +1 or +0
void solve() {
int n; cin >> n;
vector<int> v;
v.resize(n);
for (int i = 0; i < n; i++) cin >> v[i];
int x = (v[0] & 1);
for (int i = 2; i < n; i += 2) {
int j = (v[i] & 1);
if(x != j) {
cout << "NO" << endl;
return ;
}
}
int y = (v[1] & 1);
for (int i = 3; i < n; i += 2) {
int j = (v[i] & 1);
if(y != j) {
cout << "NO" << endl;
return ;
}
}
cout << "YES" << endl;
}
D Colorful Stamp
The question
: The length is n String ,RB The seal , Judge whether the string is legal . The seal can rotate ,RB,BR, And the print will cover the last time , When printing, the seal R and B Must be inside the string .
Ideas
: With W Characters separate each paragraph RB Sequence . Not in line with the situation : The length is 1, Or all R, Or all B. Other conditions can be satisfied , Provable evidence .
bool func(string s) {
if(s == "") return true;
if(s.sz == 1) return false;
if(s.find("R") == -1 || s.find("B") == -1) return false;
return true;
}
void solve() {
int n = 1; cin >> n;
string s; cin >> s;
string t = "";
for (int i = 0; i < s.sz; i++) {
if(s[i] == 'W') {
if(!func(t)) {
cout << "NO" << endl;
return ;
}
t = "";
continue;
}
t += s[i];
}
if(!func(t)) {
cout << "NO" << endl;
return ;
}
cout << "YES" << endl;
}
E 2-Letter Strings
The question
: Ask for this ( i , j ) {(i, j)} (i,j) The number of pairs , Satisfy i < j and And S i And S j only Yes One individual word operator No Same as {i<j also S_i And S_j Only one character is different } i<j and And Si And Sj only Yes One individual word operator No Same as . Violent solution .
Code 1 :
int st[30][30];
void solve() {
memset(st, 0, sizeof st);
int res = 0;
int n; cin >> n;
for (int i = 0; i < n; i++) {
string s; cin >> s;
int a = s[0] - 'a', b = s[1] - 'a';
for (int j = 0; j < 26; j++) {
if(j != a) res += st[j][b];
if(j != b) res += st[a][j];
}
st[a][b]++;
}
cout << res << endl;
}
Code 2 :
map<string, int> mp;
void solve() {
mp.clear();
int n; cin >> n;
int ans = 0;
for (int i = 0; i < n; i++) {
string s; cin >> s;
string t = s;
for (int j = 0; j < 26; j++) {
if(s[0] != j + 'a') {
t[0] = j + 'a';
ans += mp[t];
t = s;
}
if(s[1] != j + 'a') {
t[1] = j + 'a';
ans += mp[t];
t = s;
}
}
mp[s] ++;
}
cout << ans << endl;
}
F Eating Candies
The question
: The left and right find disjoint prefixes with the same value , In this case of seeking the maximum , Add up the total number of digits .
int a[N], b[N];
void solve() {
int n = 1; cin >> n;
for (int i = 0; i <= n; i++) a[i] = b[i] = 0;
for (int i = 1; i <= n; i++) cin >> a[i], b[i] = a[i];
for (int i = 1; i <= n; i++) a[i] += a[i - 1];
for (int i = n - 1; i >= 1; i--) b[i] += b[i + 1];
for (int i = 1; i <= n / 2; i++) swap(b[i], b[n - i + 1]);
int res = 0;
for (int i = 1; i <= n; i++) {
int d = lower_bound(b + 1, b + 1 + n, a[i]) - b;
if(n - d < i) break;
if(d <= n && b[d] == a[i]) {
res = i + d;
}
}
cout << res << endl;
}
G Fall Down
The question
: * Fall down , Simulation is fine
void solve() {
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> cc[i][j];
int k = 1022;
while (k--)
{
for (int i = n - 1; i >= 1; i--)
{
for (int j = 1; j <= m; j++)
{
if (cc[i][j] == '*' && cc[i + 1][j] == '.')
cc[i][j] = '.', cc[i + 1][j] = '*';
}
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++) cout << cc[i][j];
cout << endl;
}
cout << endl;
}
H Maximal AND
The question
: k operations , Each operation can select a number in the array in any bit ( < = 30 {<=30} <=30) Set up 1, Find the maximum sum of all elements of the last array .
Ideas
: greedy , From the top , In the i {i} i position Can fill 1 Just consume k Go fill in .
int n, m;
int a[N];
int s[35];
void solve() {
cin >> n >> m;
memset(s, 0, sizeof s);
for (int i = 1; i <= n; i++) {
cin >> a[i];
for (int j = 30; j >= 0; j--) {
if(a[i] >> j & 1) s[j]++;
}
}
for (int i = 30; i >= 0; i--) {
if(m + s[i] >= n) {
for (int j = 1; j <= n; j++) a[j] |= (1ll << i);
m -= n - s[i];
// Dbug(m);
}
}
int res = 0;
for (int i = 0; i <= 30; i++) res |= (1ll << i);
// for (int i = 1; i <= n; i++) {cout << a[i] << ' '; }
// cout << endl;
for (int i = 1; i <= n; i++) res &= a[i];
cout << res << endl;
}
版权声明
本文为[_ Cauchy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231902386686.html
边栏推荐
- Use of kotlin collaboration in the project
- 剑指 Offer II 116. 省份数量-空间复杂度O(n),时间复杂度O(n)
- ESP32 LVGL8. 1 - msgbox message box (msgbox 28)
- mysql通过binlog恢复或回滚数据
- [advanced level 11 of C language -- character and string functions and their simulation implementation (2)]
- Zlib realizes streaming decompression
- 腾讯云GPU最佳实践-使用jupyter pycharm远程开发训练
- Screen right-click menu in souI
- 迁移学习进阶
- Methods of nested recycleview to solve sliding conflict and incomplete item display
猜你喜欢
浅谈c语言指针的强制转换
开关电源设计分享及电源设计技巧图解
C: generic reflection
Summary of actual business optimization scheme - main directory - continuous update
[today in history] April 23: the first video uploaded on YouTube; Netease cloud music officially launched; The inventor of digital audio player was born
mysql通过binlog恢复或回滚数据
Class loading process of JVM
FTP、ssh远程访问及控制
Using Visual Studio code to develop Arduino
c#:泛型反射
随机推荐
Tencent cloud GPU best practices - remote development training using jupyter pycharm
2022.04.23(LC_714_买卖股票的最佳时机含手续费)
在渤海期货办理开户安全吗。
SSDB基础
Get a list of recent apps
Tencent map and high logo removal method
After opening the original normal project, the dependency package displays red and does not exist.
JVM的类加载过程
Xlslib use
mysql_ Download and installation of Linux version
[记录]TypeError: this.getOptions is not a function
FTP, SSH Remote Access and control
Zlib realizes streaming decompression
MVVM模型
Methods of nested recycleview to solve sliding conflict and incomplete item display
ESP32 LVGL8. 1 - slider slider (slider 22)
Use bitnami / PostgreSQL repmgr image to quickly set up PostgreSQL ha
ESP32 LVGL8. 1 - msgbox message box (msgbox 28)
How can programmers quickly develop high-quality code?
Sentinel服务熔断实战(sentinel整合ribbon+openFeign+fallback)