当前位置:网站首页>Codeforces round 784 (Div. 4) (a - H)
Codeforces round 784 (Div. 4) (a - H)
2022-04-23 02:44:00 【The day the flowers fall】
A rare time Div4, From beginning to end
A. Division?
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#define endl '\n'
using namespace std;
const int N = 1e5 + 10;
void mian()
{
int n;
cin >> n;
if (n <= 1399)
cout << "Division 4" << endl;
else if (n <= 1599)
cout << "Division 3" << endl;
else if (n <= 1899)
cout << "Division 2" << endl;
else
cout << "Division 1" << endl;
}
int main()
{
int T;
cin >> T;
while (T--)
{
mian();
}
}
B. Triple
Find three identical numbers and output , No output -1
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <unordered_map>
#define endl '\n'
using namespace std;
const int N = 1e5 + 10;
unordered_map<int, int> t;
void mian()
{
int n;
cin >> n;
t.clear();
bool flag = true;
for (int i = 1; i <= n; i++)
{
int a;
cin >> a;
t[a]++;
if (flag && t[a] >= 3)
{
cout << a << endl;
flag = false;
}
}
if (flag)
cout << -1 << endl;
}
int main()
{
int T;
cin >> T;
while (T--)
{
mian();
}
}
C. Odd/Even Increments
You can add... To all odd or even digits 1, If we can finally turn all numbers into odd or even numbers , It outputs YES
Judge whether the parity of all current odd digits is the same , Then judge all even bits
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#define endl '\n'
using namespace std;
const int N = 1e5 + 10;
void mian()
{
int n;
cin >> n;
int a, b, c;
cin >> a >> b;
bool flag = true;
for (int i = 3; i <= n; i++)
{
cin >> c;
if (i & 1)
{
if (a % 2 != c % 2)
flag = false;
}
else
{
if (b % 2 != c % 2)
flag = false;
}
}
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
int main()
{
int T;
cin >> T;
while (T--)
{
mian();
}
}
D. Colorful Stamp
You can dye two consecutive Stamps , Must be dyed in different colors , It can be dyed repeatedly , But you must have two at a time .
Scan from beginning to end , With w Division , If there is... In each substring R and B That's legal .
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#define endl '\n'
using namespace std;
const int N = 1e5 + 10;
void mian()
{
int n;
string s;
cin >> n >> s;
int b = 0, r = 0;
bool flag = true;
for (int i = 0; i < n; i++)
{
if (s[i] == 'W')
{
if (b == 0 && r != 0 || b != 0 && r == 0)
flag = false;
b = 0, r = 0;
}
else if (s[i] == 'B')
{
b++;
}
else if (s[i] == 'R')
{
r++;
}
}
if (b == 0 && r != 0 || b != 0 && r == 0)
flag = false;
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
int main()
{
int T;
cin >> T;
while (T--)
{
mian();
}
}
E. 2-Letter Strings
The question : to n A length of 2 character string , Find out how many pairs of characters in the same position are the same , Another string with different position characters .
Ideas : Save it. The first place is x Of the characters in the y The number of , And then multiply by the corresponding , Add it up . Then the second character is the same .
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#define endl '\n'
using namespace std;
typedef long long ll;
const int N = 30;
struct node
{
vector<int> num;
node()
{
num.resize(30, 0);
}
};
void mian()
{
node a[N], b[N];
int n;
cin >> n;
string s;
for (int i = 1; i <= n; i++)
{
cin >> s;
a[s[0] - 'a'].num[s[1] - 'a']++;
b[s[1] - 'a'].num[s[0] - 'a']++;
}
ll res = 0;
for (int i = 0; i <= 'k' - 'a'; i++)
{
for (int j = 0; j <= 'k' - 'a'; j++)
{
for (int k = j + 1; k <= 'k' - 'a'; k++)
{
res += 1ll * a[i].num[j] * a[i].num[k];
}
}
}
for (int i = 0; i <= 'k' - 'a'; i++)
{
for (int j = 0; j <= 'k' - 'a'; j++)
{
for (int k = j + 1; k <= 'k' - 'a'; k++)
{
res += 1ll * b[i].num[j] * b[i].num[k];
}
}
}
cout << res << endl;
}
int main()
{
int T;
cin >> T;
while (T--)
{
mian();
}
}
F. Eating Candies
The question : Two people eat candy from left to right , You can't jump to eat , Ask them if they want to eat the same weight , How many will they eat altogether .
Double pointer enumeration
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#define endl '\n'
using namespace std;
const int N = 1e5 + 10;
void mian()
{
int n;
cin >> n;
vector<int> a(n + 1, 0);
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
int res = 0, cnt = 0;
int l = 1, r = n;
int alice = 0, bob = 0;
while (l <= r)
{
if (alice == bob)
{
res = cnt;
alice += a[l++];
cnt++;
}
else if (alice > bob)
{
bob += a[r--];
cnt++;
}
else
{
alice += a[l++];
cnt++;
}
}
if (alice == bob)
{
res = cnt;
}
cout << res << endl;
}
int main()
{
int T;
cin >> T;
while (T--)
{
mian();
}
}
G. Fall Down
There are three things ,.
It's air *
It's stone ,o
I don't know what it is , You can't fall down anyway , Stones can fall , Fall on a stone or o On .
Run layer by layer , If you don't change after running, you're finished , You can quit .
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#define endl '\n'
using namespace std;
const int N = 60;
void mian()
{
int n, m;
string a[N];
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
a[i] = " " + a[i];
}
bool flag = true;
while (flag)
{
flag = false;
for (int i = n; i > 1; i--)
{
for (int j = 1; j <= m; j++)
{
if (a[i][j] == '.' && a[i - 1][j] == '*')
{
a[i][j] = '*';
a[i - 1][j] = '.';
flag = true;
}
}
}
}
for (int i = 1; i <= n; i++)
{
cout << a[i] << endl;
}
cout << endl;
}
int main()
{
int T;
cin >> T;
while (T--)
{
mian();
}
}
H. Maximal AND
That is, any binary bit of a number in the array can be changed into 1, Find the maximum sum of this pile of numbers . Can change k Time .
Save each bit of the binary bits of all numbers into an array , If that one in the array reaches n 了 , It shows that the final one is 1, then k Add greedily at once , If you add it all in, you can't get to n, Then change to a lower one .
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#define endl '\n'
using namespace std;
const int N = 1e5 + 10;
void mian()
{
int a[40] = {
0};
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++)
{
int t;
cin >> t;
int idx = 0;
while (t)
{
a[idx++] += (t & 1);
t >>= 1;
}
}
for (int i = 30; i >= 0; i--)
{
if (a[i] + k >= n)
{
k -= n - a[i];
a[i] = n;
}
if (k <= 0)
break;
}
int res = 0;
int t = 1;
for (int i = 0; i <= 30; i++)
{
if (a[i] == n)
res += t;
t <<= 1;
}
cout << res << endl;
}
int main()
{
int T;
cin >> T;
while (T--)
{
mian();
}
}
版权声明
本文为[The day the flowers fall]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230241136318.html
边栏推荐
- Slave should be able to synchronize with the master in tests/integration/replication-psync.tcl
- [XJTU computer network security and management] Lecture 2 password technology
- So library dependency
- First day of rhcsa
- Windows MySQL 8 zip installation
- [unity3d] rolling barrage effect in live broadcasting room
- 牛客手速月赛 48 C(差分都玩不明白了属于是)
- 字符串去掉空格问题
- mysql function函数语法
- 学习正则表达式选项、断言
猜你喜欢
JVM运行时数据区(一)
[unity3d] rolling barrage effect in live broadcasting room
Looking for a job, writing a resume to an interview, this set of information is enough!
Global, exclusive and local routing guard
RT_ Thread ask and answer
The usage and difference of * and & in C language and the meaning of keywords static and volatile
Real math problems in 1958 college entrance examination
Huashu "deep learning" and code implementation: 01 Linear Algebra: basic concepts + code implementation basic operations
机器学习(周志华) 第十四章概率图模型
重大危险源企业如何保障年底前完成双预防机制数字化建设任务
随机推荐
JVM运行时数据区(一)
第46届ICPC亚洲区域赛(昆明) B Blocks(容斥+子集和DP+期望DP)
MySQL复杂查询使用临时表/with as(类似表变量)
Niuke hand speed monthly race 48 C (I can't understand the difference. It belongs to yes)
魔王冷饭||#078 魔王答上海、南京行情;沟通指导;得国和打杀筛选;赚钱的目的;改变别人看法
[XJTU計算機網絡安全與管理]第二講 密碼技術
Efficient music format conversion tool Music Converter Pro
5W of knowledge points
JZ35 replication of complex linked list
Log4j knowledge point record
Handwritten memory pool and principle code analysis [C language]
ROP Emporium x86_64 7~8题
双亲委派模型【理解】
JZ76 删除链表中重复的结点
leangoo脑图-共享式多人协作思维导图工具分享
Program design: l1-49 ladder race, allocation of seats (simulation), Buxiang pill hot
Halo open source project learning (I): project launch
MySQL function syntax
Preliminary understanding of stack and queue
Probabilistic model of machine learning