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 ...
随机推荐
- 2020-04-29:现在你有个秒杀抢购的app,用户不断大量增加,技术层面,你要怎么做
2020-04-29:现在你有个秒杀抢购的app,用户不断大量增加,技术层面,你要怎么做,才能既满足用户需求,又能扛住压力,还能帮公司合理支出?福哥答案2020-04-29: 限流(杀部分用户祭天). ...
- C#LeetCode刷题之#434-字符串中的单词数(Number of Segments in a String)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3941 访问. 统计字符串中的单词个数,这里的单词指的是连续的不是 ...
- noip复习——快速幂
\(a ^ n \bmod p\) \(a, p, n \leq 10^9\) 最普通的二进制拆分 #define LL long long LL qpow(LL a, LL n, LL p) { L ...
- three.js 着色器材质内置变量
这篇郭先生说一下three.js着色器的内置变量,分别是 gl_PointSize:在点渲染模式中,控制方形点区域渲染像素大小(注意这里是像素大小,而不是three.js单位,因此在移动相机是,所看到 ...
- TypeScript是什么,为什么要使用它?
转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 原文出处:https://medium.com/swlh/what-is-typescript-bf333e ...
- SpringBoot--- Shiro(拦截,认证)、Thymeleaf(模板引擎)
SpringBoot--- Shiro(拦截,认证).Thymeleaf(模板引擎) 环境 IDEA :2020.1 SpringBoot: 2.3.3 Java : 8 版本依赖: shiro- ...
- keepalived的vrrp多播报文被禁,导致VIP同时位于多个机器上
keepalived的vrrp多播报文被禁,导致VIP同时位于多个机器上 查看man keepalived.conf,VRRP instances中给出了单播的设置方法,添加unicast_peer即 ...
- Java实现树形结构的数据转Json格式
在项目中难免会用到树形结构,毕竟这是一种常用的组织架构.楼主这里整理了两个实现的版本,可以直接拿来使用,非常方便. 楼主没有单独建项目,直接在以前的一个Demo上实现的.第一种,看下面代码: pack ...
- 第4篇 Scrum 冲刺博客
1.站立会议 照骗 进度 成员 昨日完成任务 今日计划任务 遇到的困难 钟智锋 重新设计项目执行流程 实现技能 庄诗楷 游戏窗口的制作 制作了开始游戏的界面,感觉还不错 无 易德康 完成所有棋子的移动 ...
- 用 Python 写个七夕表白神器
今天是七夕节,相比于现代人自创的 502,不对是 520,七夕才是中国传统意义上的情人节,本文分享几个 Python 表白程序,情侣可以现学现用,单身的话也可以先收藏一下,说不定下次就用上了. 爱心树 ...