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 ...
随机推荐
- C#LeetCode刷题之#387-字符串中的第一个唯一字符(First Unique Character in a String)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3939 访问. 给定一个字符串,找到它的第一个不重复的字符,并返回 ...
- Probabilistic PCA、Kernel PCA以及t-SNE
Probabilistic PCA 在之前的文章PCA与LDA介绍中介绍了PCA的基本原理,这一部分主要在此基础上进行扩展,在PCA中引入概率的元素,具体思路是对每个数据$\vec{x}_i$,假设$ ...
- 01第一个批处理文件 window开机自动加载批处理文件
1 批处理文件用来加载python程序 批处理的文件名称为:Hello.bat @echo off C: cd C:\Users\\Desktop\python\HelloWorld\HelloWo ...
- Typora markdown代码块显示序号
打开偏好设置,找到代码块 打开显示行号 然后关闭Typora重新打开 此时代码块就有行号了
- Spark从入门到放弃---RDD
什么是Spark? 关于Spark具体的定义,大家可以去阅读官网或者百度关于Spark的词条,在此不再赘述.从一个野生程序猿的角度去理解,作为大数据时代的一个准王者,Spark是一款主流的高性能分布式 ...
- 用python进行实际地址经纬度提取
实际地址经纬度提取 请求接口: https://apis.map.qq.com/ws/place/v1/suggestion/ 所需参数: 参数名称 是否必须 参数类型 说明 keyword 是 St ...
- Oracle 多条数据转一行逗号隔开
wm_concat 例: select wm_concat(市) from pa50 where apa132=省
- golang grpc demo
1.grpm 安装: git clone https://github.com/grpc/grpc-go.git $GOPATH/src/google.golang.org/grpc 2.proto, ...
- The Successor Representation: Its Computational Logic and Neural Substrates
郑重声明:原文参见标题,如有侵权,请联系作者,将会撤销发布! Received May 14, 2018; revised June 28, 2018; accepted July 5, 2018.T ...
- Mysql锁【转】
一.概述 数据库锁定机制简单来说,就是数据库为了保证数据的一致性,而使各种共享资源在被并发访问变得有序所设计的一种规则.对于任何一种数据库来说都需要有相应的锁定机制,所以MySQL自然也不能例外. M ...