当前位置:网站首页>Codeforces Round #784 (Div. 4) (A - H)题解
Codeforces Round #784 (Div. 4) (A - H)题解
2022-04-23 02:41:00 【花落的那一天】
难得的一次Div4,从头写到尾
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
找三个相同的数然后输出,没有就输出-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
可以给所有奇数位或偶数位加1,如果能最终把所有数都变成奇数或者偶数,就输出YES
判断当前所有奇数位的数的奇偶性是不是一样,然后判断所有偶数位
#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
可以给连续两张邮票染色,必须染不同的色,可以重复染,但是一次必须连续两张。
从头到尾扫描一遍,以w分割,每个子串中如果有R和B那就是合法的。
#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
题意:给n个长度为2字符串,找出多少对同一个位置字符相同,另一个位置字符不同的字符串。
思路:存一下第一个位置为x的字符中字符y的个数,然后对应相乘,再加到一起。然后第二个字符同理。
#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
题意:两人分别从左边右边开始吃糖果,不能跳着吃,问他们想要吃的重量一样,他们一共要吃多少个。
双指针枚举即可
#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
有三种东西,.
是空气*
是石头,o
不知道是啥,反正不能掉下来,石头能掉下来,掉到石头上或者o上。
一层一层跑,如果跑一遍没变化就是跑完了,可以退出了。
#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
就是可以给数组中一个数的二进制任意一位变成1,求这一堆数求与最大能变为多少。可以变k次。
存一下所有数的二进制位的每一位到一个数组,如果数组中的那一个达到n了,说明最终的这一位是1,然后k次就贪心的添加,如果全加进去不能到n,那就换低一位的。
#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();
}
}
版权声明
本文为[花落的那一天]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Ghost_Darkgreen/article/details/124335438
边栏推荐
- Six very 6 computer driver managers: what software is good for driver upgrade? Recommended by the best computer driver management software abroad
- php+mysql对下拉框搜索的内容修改
- JZ22 鏈錶中倒數最後k個結點
- [XJTU計算機網絡安全與管理]第二講 密碼技術
- Real math problems in 1958 college entrance examination
- Parental delegation model [understanding]
- 进阶上将程序员必备素质
- 全局、獨享、局部路由守衛
- 全局、独享、局部路由守卫
- C language 171 Number of recent palindromes
猜你喜欢
Understanding process (multithreading primary)
Flink stream processing engine system learning (III)
C语言中*与&的用法与区别 以及关键字static和volatile 的含义
高效音乐格式转换工具Music Converter Pro
16、 Anomaly detection
[XJTU computer network security and management] Lecture 2 password technology
Day18 -- stack queue
Real math problems in 1958 college entrance examination
定了,今日起,本号粉丝可免费参与网易数据分析培训营!
Flink stream processing engine system learning (II)
随机推荐
Classification and regression tree of machine learning
学习正则表达式选项、断言
本地远程访问云服务器的jupyter
Global, exclusive and local routing guard
WordPress calls the specified page content. 2 get_ children()
Fashion MNIST 数据集分类训练
php+mysql對下拉框搜索的內容修改
Real math problems in 1958 college entrance examination
Day18 -- stack queue
智能辅助功能丰富,思皓X6安全配置曝光:将于4月23日预售
MySQL JDBC programming
C language 171 Number of recent palindromes
1215_ Hello world used by scons
Solve the problem that the registered Google email Gmail mobile number cannot be used for verification
Store consumption SMS notification template
程序设计天梯赛 L1-49 天梯赛分配座位(模拟),布响丸辣
Using go language to build web server
Six very 6 computer driver managers: what software is good for driver upgrade? Recommended by the best computer driver management software abroad
解决win7 中powershell挖矿占用CPU100%
[xjtu Computer Network Security and Management] session 2 Cryptographic Technology