当前位置: 首页 > news >正文

Codeforces Round 899 (Div. 2)

Dashboard - Codeforces Round 899 (Div. 2) - Codeforces

A. Increasing Sequence

由于a与b不相等,但b必须算出最小故可以从最小开始(1),故如果b = a就将其值++,使其改变即可,其余由于b1 < b2 < b3...顺着赋值即可

#include<bits/stdc++.h>
using namespace std;
const int N = 1e7 + 10; 
int b[N], a[N];
void solve()
{int n, cnt = 0;cin >> n;for(int i = 1; i <= n; i ++){cin >> a[i];}int k = 1;for(int i = 1; i <= n; i ++){if(k != a[i]){b[i] = k;k ++;}else{k ++;b[i] = k;k ++;}}cout << b[n] << '\n';
}
int main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);int t;cin >> t;while(t --){solve();}return 0;
}

B. Sets and Union

对于每一个集合,我们可以先将这些集合中的数都存放在v[i]这个数组里,每一个i代表了一个集合,再将集合中有哪些数存在set中,因为set自动排序去重,我们可以不重的在set中看到每个数的存储,我们要找到几个集合的交集使其有最大的元素,最好的方案就是在所有元素中去掉一个元素,我们可以枚举每一个元素,看它在每个集合中是否出现,将没有出现过这个元素的集合全部相加,每找一个元素就比较一个元素,找到最大的缺少这个元素的集合的数为答案(将没有这个数的集合的元素存入set(ss),set(ss)会自动去重),最大值即为答案

#include<bits/stdc++.h>
using namespace std;
void solve()
{int n, ans = 0;int s, len;vector<int> v[100];vector<int> v1;cin >> n;for(int i = 0; i < n; i ++){cin >> len;for(int j = 0; j < len; j ++){cin >> s;v[i].push_back(s);}}set<int>st;for(int i = 0; i < n; i ++){for(auto j : v[i]){st.insert(j);	}	}for(int i : st){set<int> ss;ss.clear();int x = i;for(int j = 0; j < n; j ++){int flag = 1;for(auto k : v[j]){if(k == x)flag = 0;}if(flag){for(auto o : v[j]){ss.insert(o);}}}ans = max(ans, (int)ss.size()); }cout << ans << '\n';
}
int main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);int t;cin >> t;while(t --){solve();}return 0;
}

C. Card Game

题意:奇数位的a[i]进行删除并获得分数,偶数位的a[i]只用删除即可

eg.1 2 3 4 5

会发现奇数位可以算上自己以及后面的所有正整数

偶数位可以算上出自己之外的所有正整数

进行后缀和的维护即可

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
void solve()
{ll n, a[N], s[N];memset(a, 0, sizeof a);memset(s, 0, sizeof s);cin >> n;for(int i = 1; i <= n; i ++)cin >> a[i];for(int i = n; i >= 1; i --)s[i] += max(s[i + 1], s[i + 1] + a[i]);ll ans = 0;for(int i = 1; i <= n; i ++){if(i % 2){ans = max(ans, a[i] + s[i + 1]);}else ans = max(ans, s[i + 1]);}cout << ans << '\n';
}
int main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);int t;cin >> t;while(t --){solve();}return 0;
}
http://www.lryc.cn/news/179976.html

相关文章:

  • 【 SuperPoint 】图像特征提取上的对比实验
  • Chrome获取RequestId
  • cesium 雷达扫描 (线行扩散效果)
  • 【React】React组件生命周期以及触发顺序(部分与vue做比较)
  • 【C++】多线程的学习笔记——白话文版(bushi
  • 图像处理: ImageKit.NET 3.0.10704 Crack
  • K8S内容分发网络之集群,nginx,负载均衡,防火墙
  • 不愧是疑问解决神器!你强任你强
  • 盛最多水的容器 接雨水【基础算法精讲 02】
  • WordPress主题开发( 十二)之—— 主题的functions.php
  • 代码的工厂模式
  • UE5.1编辑器拓展【一、脚本化资产行为,通知,弹窗,高效复制多个同样的资产】
  • mac openssl 版本到底怎么回事 已解决
  • AWS】在EC2上创建root用户,并使用root用户登录
  • 9月24日回顾
  • Spring注册Bean系列--方法1:@Component
  • 防火墙基础之H3C防火墙和三层交换机链路聚合的配置
  • 管理类联考——数学——汇总篇——知识点突破——算数——记忆
  • leetCode 455.分发饼干 贪心算法
  • vue3简易文字验证码
  • Java 23种设计模式分类概括以及应用介绍
  • 运筹优化算法常用求解器汇总
  • 字符串函数(一)
  • Ubuntu 安装 Docker 的详细步骤
  • 使用Python进行App用户细分
  • 博弈论——伯特兰德寡头模型(Bertrand Model)
  • 第一百六十回 SliverPadding组件
  • Mapfree智驾方案,怎样实现成本可控?
  • javascript: Bubble Sort
  • DM数据库根据rowid删除重复的记录