Codeforces Round #670 (Div. 2) 深夜掉分(A - C题补题)
1406A. Subset Mex
https://codeforces.com/contest/1406/problem/A

Example
input
4
6
0 2 1 5 0 1
3
0 1 2
4
0 2 0 1
6
1 2 3 4 5 6
output
5
3
4
0
Note
In the first test case,\(A=\{0,1,2\},B=\{0,1,5\}\) is a possible choice.
In the second test case, \(A=\{0,1,2\},B=∅\) is a possible choice.
In the third test case, \(A=\{0,1,2\},B=\{0\}\) is a possible choice.
In the fourth test case,$ A={1,3,5},B={2,4,6}$ is a possible choice.
题意:
给定一个集合,并定义 \(mex\) 操作:集合中的最小非负数。
如:\(mex(\{1,4,0,2,2,1\})=3\)
求 集合分为两部分的最大值:\(max( mex(A) + mex(B) )\)
思路:
通过维护两个变量从0开始,如果有0、1、2、3...这样的直接慢慢向上叠加
#include<bits/stdc++.h>
#define ms(a,b) memset(a,b,sizeof a)
using namespace std;
typedef long long ll;
const int N = 1e5 + 100;
ll n, a[N];
void solve() {
cin >> n;
for (int i = 0; i < n; ++i)cin >> a[i];
sort(a, a + n);
ll m = 0, k = 0;
for (int i = 0; i < n; ++i) {
if (a[i] == m)m++;
else if (a[i] == k)k++;
}
cout << m + k << endl;//m、k相当于两个集合中的非负最小值
}
int main() {
//freopen("in.txt", "r", stdin);
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
ll _; cin >> _;
while (_--)solve();
}
1406B. Maximum Product
https://codeforces.com/contest/1406/problem/B

Example
input
4
5
-1 -2 -3 -4 -5
6
-1 -2 -3 1 2 -1
6
-1 0 0 0 -1 -1
6
-9 -7 -5 -3 -2 1
output
-120
12
0
945
Note
In the first test case, choosing \(a1,a2,a3,a4,a5\) is a best choice: \((−1)⋅(−2)⋅(−3)⋅(−4)⋅(−5)=−120\).
In the second test case, choosing \(a1,a2,a3,a5,a6\) is a best choice: \((−1)⋅(−2)⋅(−3)⋅2⋅(−1)=12\).
In the third test case, choosing\(a1,a2,a3,a4,a5\) is a best choice: \((−1)⋅0⋅0⋅0⋅(−1)=0\).
In the fourth test case, choosing \(a1,a2,a3,a4,a6\) is a best choice: \((−9)⋅(−7)⋅(−5)⋅(−3)⋅1=945\).
题意:
给定 大小为n的一个数组,求下标 \((i,j,k,l,t) (i<j<k<l<t).\) 使得\(a1,a2,a3,a4,a5\) 最大
思路:
一开始以为不能排序,搞得卡了好久。
先对所给数组进行排序,这样必然倒数5个最大,又因为存在负数的关系,所以也许 $ - * - $ 反而最大。详情见代码
#include<bits/stdc++.h>
#define ms(a,b) memset(a,b,sizeof a)
using namespace std;
typedef long long ll;
const int N = 1e5 + 100;
ll n, a[N];
void solve() {
cin >> n; ll ans[4] = {};
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
ans[0] = a[n] * a[n - 1] * a[n - 2] * a[n - 3] * a[n - 4];
ans[1] = a[n] * a[n - 1] * a[n - 2] * a[1] * a[2];
ans[2] = a[n] * a[1] * a[2] * a[3] * a[4];
sort(ans, ans + 3); cout << ans[2] << endl;
}
int main() {
//freopen("in.txt", "r", stdin);
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
ll _; cin >> _;
while (_--)solve();
}
1406C. Link Cut Centroids
https://codeforces.com/contest/1406/problem/C
题目太长这里不粘贴了。
题意:
思路:
DFS搜索,详细待补。请先阅读代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 10;
int n;
int p1, p2, p3, c[N];
vector<int>g[N];
void dfs(int u, int fa) {
c[u] = 1;
for (auto v:g[u]) if (v != fa) {
dfs(v, u), c[u] += c[v];
}
if (!p3) {
if (c[u] == 1) p1 = fa, p2 = u;
if (n - c[u] == c[u]) p3 = fa;
}
}
signed main() {
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
cin >> n;
p1 = p2 = p3 = 0;
for (int i = 1; i <= n; i++) g[i].clear(), c[i] = 0;
for (int i = n; --i;) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(1, -1);
cout << p1 << ' ' << p2 << '\n' << p2 << ' ' << (p3 ? p3 : p1) << '\n';
}
return 0;
}
Codeforces Round #670 (Div. 2) 深夜掉分(A - C题补题)的更多相关文章
- Codeforces Round 480 Div 2 光荣掉分记
痛 痛苦 痛苦啊. 越接近黄名想的越多了啊…… 都说了不要在意rating这破玩意了…… 没出E就算了,策略问题. 居然还FST了: FST个D就算了: FST个A算个**啊. 紧张的时候总会写出一些 ...
- Codeforces Round #670 (Div. 2) D. Three Sequences 题解(差分+思维+构造)
题目链接 题目大意 给你一个长为n的数组a,要你构造一个非严格单调上升的数组b和一个非严格单调下降的数组c,使得\(b_i+c_i=a_i\) 要你使这两个数组b,c中最大的元素最小,还有q次修改(q ...
- Codeforces Round #670 (Div. 2) C. Link Cut Centroids (dfs,树)
C. Link Cut Centroids Fishing Prince loves trees, and he especially loves trees with only one centro ...
- Codeforces Round #670 (Div. 2) B. Maximum Product (暴力)
题意:有一长度为\(n\)的序列,求其中任意五个元素乘积的最大值. 题解:先排序,然后乘积能是正数就搞正数,模拟一下就好了. 代码: int t; ll n; ll a[N]; int main() ...
- Codeforces Round #670 (Div. 2) A. Subset Mex (贪心)
题意:给你一长度为\(n\)的序列,将其分为两个集合,求两个集合中未出现的最小元素的最大值, 题解:用桶存一下每个元素的个数,两次枚举\([1,100]\),找出两个最小值即可. 代码: int t; ...
- Codeforces Round #427 (Div. 2)—A,B,C,D题
A. Key races 题目链接:http://codeforces.com/contest/835/problem/A 题目意思:两个比赛打字,每个人有两个参数v和t,v秒表示他打每个字需要多久时 ...
- Codeforces Round #707 (Div. 2)A.英语漏洞 + C.Going Home C题收获不小
A题英语漏洞 A题传送门: https://codeforces.com/contest/1501/problem/A 其实题目说的很明白, 只是我傻傻的会错了意, 话不多说, 开整. 前两行是说, ...
- Codeforces Round #369 (Div. 2)---C - Coloring Trees (很妙的DP题)
题目链接 http://codeforces.com/contest/711/problem/C Description ZS the Coder and Chris the Baboon has a ...
- Codeforces Round #385 (Div. 2) A. Hongcow Learns the Cyclic Shift 水题
A. Hongcow Learns the Cyclic Shift 题目连接: http://codeforces.com/contest/745/problem/A Description Hon ...
随机推荐
- 为什么我们需要Q#?
原文地址:https://blogs.msdn.microsoft.com/visualstudio/2018/11/15/why-do-we-need-q/ 本文章为机器翻译. 你可能熟悉微软量子的 ...
- C#LeetCode刷题-动态规划
动态规划篇 # 题名 刷题 通过率 难度 5 最长回文子串 22.4% 中等 10 正则表达式匹配 18.8% 困难 32 最长有效括号 23.3% 困难 44 通配符匹配 17.7% ...
- 【NOI2004】郁闷的出纳员 - Splay
题目描述 OIER公司是一家大型专业化软件公司,有着数以万计的员工.作为一名出纳员,我的任务之一便是统计每位员工的工资.这本来是一份不错的工作,但是令人郁闷的是,我们的老板反复无常,经常调整员工的工资 ...
- 用心整理的 献丑啦 一些关于http url qs fs ...模块的方法
http: const http = require("http"); http.createServer((req , res)=>{ req:request 请求 ...
- YApi——手摸手,带你在Win10环境下安装YApi可视化接口管理平台
手摸手,带你在Win10环境下安装YApi可视化接口管理平台 YApi YApi 是高效.易用.功能强大的 api 管理平台,旨在为开发.产品.测试人员提供更优雅的接口管理服务.可以帮助开发者轻松创建 ...
- PHP基础之常量与变量
1.变量:用来存储信息的空间大小 $var 2.常量:定义之后不可以更改,标识符,并且给其赋值,常量是全局,在整个页面中均可使用,常量一般有英文字母.下划线.数字组成,开头不能是数字和$ 使用defi ...
- 手把手教你使用VUE+SpringMVC+Spring+Mybatis+Maven构建属于你自己的电商系统之vue后台前端框架搭建——猿实战01
猿实战是一个原创系列文章,通过实战的方式,采用前后端分离的技术结合SpringMVC Spring Mybatis,手把手教你撸一个完整的电商系统,跟着教程走下来,变身猿人找到工作不是 ...
- C++ Templates (1.7 总结 Summary)
返回完整目录 目录 1.7 总结 Summary 1.7 总结 Summary 函数模板定义了一系列不同模板实参的函数 当传递实参给依赖于模板参数的函数参数,函数模板推断模板参数并实例化相应的参数类型 ...
- 线程池之Executor框架
线程池之Executor框架 Java的线程既是工作单元,也是执行机制.从JDK5开始,把工作机单元和执行机制分离开来.工作单元包括Runnable和Callable,而执行机制由Executor框架 ...
- 虚拟化技术之kvm虚拟机创建工具qemu-kvm
在前边的博客中我们介绍了如何创建kvm虚拟机,以及一些常用的工具的介绍和使用,今天我们来了解下kvm原始工具qemu-kvm:为什么说qemu-kvm是一个原始的工具呢,如果你用kvm虚拟机,心细的你 ...