当前位置:网站首页>CodeCraft-22 and Codeforces Round #795 (Div. 2)
CodeCraft-22 and Codeforces Round #795 (Div. 2)
2022-06-10 17:21:00 【AMjieker】
A
思路: 任意相邻元素之和为偶数,那么这两个数定是两个偶数或者奇数,也就意味者整个序列只能有奇数或者偶数。
signed main(){
cin >> t;
while (t --) {
cin >> n;
int a = 0, b = 0;
for (int i = 1; i <= n; i ++) {
cin >> x;
if (x % 2) a ++;
else b ++;
}
cout << min(a, b) << endl;
}
return 0;
}
B
思路:要求每个人之间换一个数,每个人只能换大于等于他的数,那么这就意味着,只能换等于他的数,因为换大于他的数,原来的那个人就只有去找更大的了,最后,一定会有一个人找不到数可以换。
每个人对于和他自己相等的数,移动一个位置即可
signed main(){
tle
cin >> t;
while (t --) {
cin >> n;
map<int, vector<int>> mp;
for (int i = 1; i <= n; i ++) cin >> x, mp[x].push_back(i);
int f = 1;
for (auto& t : mp)
if (t.second.size() < 2) f = 0;
else {
auto& p = t.second;
int l = p.size();
for (int i = 0; i < l; i ++)
s[p[i]] = p[(i + 1)%l];
}
if (f) {
for (int i = 1; i <= n; i ++) cout << s[i] << " ";
cout << endl;
} else cout << -1 << endl;
}
return 0;
}
C
思路:01100 和 01010 其实没有区别,区别在于消除头和尾部的0
消除尾部的0,赚10
消除头部的0,赚1
头尾消除完就没了
signed main(){
tle
cin >> t;
while (t --) {
cin >> n >> k;
string s;int ans = 0;
cin >> s;
for (int i = n - 1; i >= 0; i --) {
if (s[i] == '1') {
int st = i;
if (i + k >= n - 1) {
swap(s[i], s[n - 1]);
k -= n - 1 - i;
st --;
}
for (int j = 0; j <= st; j ++) {
if (s[j] == '1'){
if (k >= j)
swap(s[j], s[0]);
break;
}
}
break;
}
}
for (int i = 0; i < n - 1; i ++) {
if (s[i] == '1' && s[i + 1] == '1') ans += 11;
else if(s[i] == '1' && s[i + 1] == '0') ans += 10;
else if (s[i] == '0' && s[i + 1] == '1') ans += 1;
}
cout << ans << endl;
}
return 0;
}
D
思路:找出一段和大于这一段的max。对于一段的和,在某一个区间内
找出以[i, r]范围内某一个点的最大前缀和去减去[l, i-1]范围内的最小的前缀和。 为保证i点为最大,我们需要找到i左边和i右边大于i的第一个数。
这个点上,可以用单调栈来求。
某一段上的最大值和最小值,可以用st表来求。
int k;
int l[N], r[N], st[N], idx;
int mins[N][31], maxs[N][31], pre[N];
signed main(){
tle
cin >> t;
pre[1] = 0;
pre[2] = 1;
for (int i = 3; i < N; i ++) pre[i] = pre[i / 2] + 1;
while (t --) {
cin >> n;
for (int i = 1; i <= n; i ++)
cin >> g[i], s[i] = s[i - 1] + g[i],
mins[i][0] = maxs[i][0] = s[i];
st[0] = 0;
for (int i = 1, idx = 0; i <= n; i ++) {
while(idx && g[st[idx]] <= g[i]) idx --;
l[i] = st[idx];
st[++ idx] = i;
}
st[0] = n + 1;
for (int i = n, idx = 0; i >= 1; i --) {
while(idx && g[st[idx]] <= g[i]) idx --;
r[i] = st[idx];
st[++ idx] = i;
}
for (int j = 1; (1 << j) <= n; j ++)
for (int i = 1; i + (1 << j) - 1 <= n; i ++) {
mins[i][j] = min(mins[i][j - 1], mins[i + (1 << (j - 1))][j - 1]);
maxs[i][j] = max(maxs[i][j - 1], maxs[i + (1 << (j - 1))][j - 1]);
}
int f = 1;
for (int i = 1; i <= n && f; i ++) {
int zl = l[i], zr = r[i] - 1, j, a = 0, b = 1e18;
j = pre[zr - i + 1];
a = max(maxs[i][j], maxs[zr - (1 << j) + 1][j]);
if (!zl) zl ++, b = 0;
j = pre[i - zl];
if (i != zl)
b = min(b, min(mins[zl][j], mins[i - (1 << j)][j]));
//printf("%lld %lld | %lld %lld\n", a, b, zl, zr);
if (g[i] < a - b) f = 0;
}
cout << (f ? "YES" : "NO") << endl;
}
return 0;
}
边栏推荐
- 4. ssh
- 线性移动棋
- THE LOTTERY TICKET HYPOTHESIS: FINDING SPARSE, TRAINABLE NEURAL NETWORKS论文笔记
- Unity踩坑记录:如果继承MonoBehaviour,类的构造函数可能会被Unity调用多次,不要在构造函数做初始化工作
- Vim常用命令总结
- The latest good article | interpretable confrontation defense based on causal inference
- 【FAQ】运动健康服务REST API接口使用过程中常见问题和解决方法总结
- matplotlib plt.text()的具体用法——画图时给图中的点加标签
- 【AXI】解读AXI协议双向握手机制的原理
- Leetcode 875. 爱吃香蕉的珂珂
猜你喜欢

Penguin E-sports stops, and tiger teeth are hard to walk

matplotlib plt.text()的具体用法——画图时给图中的点加标签

AI 加持实时互动|ZegoAvatar 面部表情随动技术解析

js锚点定位可以扩展很多功能

How will you integrate into the $20trillion "project economy" in five years

正斜杠“/”、反斜杠“\、”转义字符“\”、文件路径分割符傻傻记不清楚

IIS installation and deployment web site

聊聊消息中间件(1),AMQP那些事儿

基于Feign远程调用

mmcv之Registry类解读
随机推荐
The short ticket hypothesis: finding sparse, trainable neural networks
Swin_Transformer源码解读
Abbexa 无细胞 DNA 试剂盒说明书
玩轉Pytorch的Function類
Analysis of transfer Refund Scheme in e-commerce industry
嘿!ONES 新星请看过来|师兄师姐说
Leetcode String to integer(Atoi)
开源项目 PM 浅谈如何设计官网
Mapbox GL development tutorial (11): loading line layers
高数_第6章无穷级数__绝对收敛_条件收敛
蓝桥杯_糊涂人寄信_递归
力扣 20. 有效的括号
JS blur shadow follow animation JS special effect plug-in
THE LOTTERY TICKET HYPOTHESIS: FINDING SPARSE, TRAINABLE NEURAL NETWORKS论文笔记
Can the "no password era" that apple is looking forward to really come true?
Force buckle 20 Valid parentheses
Leetcode String to integer(Atoi)
js手机端复制文本到剪切板代码
Nacos配置管理
LeetCode 255. 验证前序遍历序列二叉搜索树*