当前位置:网站首页>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
边栏推荐
- Introduction to micro build low code zero Foundation (lesson 3)
- 高层次人才一站式服务平台开发 人才综合服务平台系统
- 从技术体系到商业洞察,中小研发团队架构实践之收尾篇
- Resolution: cnpm: unable to load file \cnpm. PS1, because running scripts is prohibited on this system
- Advanced transfer learning
- Esp01s with Arduino development environment
- How can programmers quickly develop high-quality code?
- PyGame tank battle
- [mathematical modeling] - analytic hierarchy process (AHP)
- 【历史上的今天】4 月 23 日:YouTube 上传第一个视频;网易云音乐正式上线;数字音频播放器的发明者出生
猜你喜欢
FTP, SSH Remote Access and control
From technical system to business insight, the closing chapter of the practice of small and medium-sized R & D team structure
MySQL Téléchargement et installation de la version Linux
七、DOM(下) - 章节课后练习题及答案
WebView opens H5 video and displays gray background or black triangle button. Problem solved
Android Development: the client obtains the latest value in the database in real time and displays it on the interface
Some records used by VS2010
ESP32 LVGL8. 1. Detailed migration tutorial of m5stack + lvgl + IDF (27)
redis优化系列(三)解决主从配置后的常见问题
mysql通过binlog恢复或回滚数据
随机推荐
ESP32 LVGL8. 1. Detailed migration tutorial of m5stack + lvgl + IDF (27)
解决:cnpm : 無法加載文件 ...\cnpm.ps1,因為在此系統上禁止運行脚本
中金财富怎么样?在上边开户安全吗
七、DOM(下) - 章节课后练习题及答案
该买什么设备,Keysight 给你挑好了
ESP32 LVGL8. 1 - img picture (IMG 20)
Deeply understand what new and make in golang are and what are the differences?
Advanced transfer learning
C1000k TCP connection upper limit test 1
WebView opens H5 video and displays gray background or black triangle button. Problem solved
Seata处理分布式事务
c1000k TCP 连接上限测试1
How about CICC wealth? Is it safe to open an account up there
Methods of nested recycleview to solve sliding conflict and incomplete item display
: app: transformclasseswithrobustfordevrease meituan hot repair compilation error record
简化路径(力扣71)
Machine learning practice - naive Bayes
Sentinel service fusing practice (sentinel integration ribbon + openfeign + fallback)
Accessing private members using templates
Druid SQL和Security在美团点评的实践