Codeforces Round #633 (Div. 2)
Codeforces Round #633(Div.2)
\(A.Filling\ Diamonds\)
答案就是构成的六边形数量+1
//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
using LL = int_fast64_t;
void solve(){
LL n; cin >> n;
cout << n << endl;
}
int main(){
____();
int T;
for(cin >> T; T; T--) solve();
return 0;
}
\(B.Sorted\ Adjacent\ Differences\)
考虑排完序之后从中间开始一左一右选择即可
//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 2e5+7;
int n,A[MAXN];
void solve(){
cin >> n;
for(int i = 1; i <= n; i++) cin >> A[i];
sort(A+1,A+1+n);
int mid = n / 2 + 1;
int lp = mid - 1, rp = mid + 1;
cout << A[mid] << ' ';
while(lp!=0 or rp!=n+1){
if(lp!=0) cout << A[lp--] << ' ';
if(rp!=n+1) cout << A[rp++] << ' ';
}
cout << endl;
}
int main(){
____();
int T;
for(cin >> T; T; T--) solve();
return 0;
}
\(C.Powered\ Addition\)
考虑对于每个数,需要加的最小值为其之前的最大值和这个值的差值,然后找到这个差值的最大值找到其二进制最高位即可
//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 1e5+7;
using LL = int_fast64_t;
int n;
LL A[MAXN];
void solve(){
cin >> n;
for(int i = 1; i <= n; i++) cin >> A[i];
LL minn = 1e10;
LL delta = 0;
for(int i = n; i >= 1; i--){
delta = max(delta,A[i]-minn);
minn = min(A[i],minn);
}
if(!delta) cout << 0 << endl;
else{
while(delta!=(delta&-delta)) delta -= (delta&-delta);
cout << __builtin_ctz(delta)+1 << endl;
}
}
int main(){
____();
int T;
for(cin >> T; T; T--) solve();
return 0;
}
\(D.Edge\ Weight\ Assignment\)
考虑最少不同的数,各个叶子节点到根的距离的奇偶性如果一样,那么所有边权都可以相等,否则的话用\(1,2,3\)三个数来赋值边权必然可以满足条件
对于最多的不同的数,考虑树形\(DP\),\(dp[i]\)表示以\(i\)为根的子树所用的最多的不同边权,以非叶节点为根进行\(dfs\),考虑转移,对于\(u\)点的所有儿子,如果存在叶子节点的话,\(dp[u]+=1\),叶子节点连上来的边权必然相等,对于儿子中的非叶子节点\(v\),转移为\(dp[u] += dp[v] + 1\),可以假设叶子节点走到儿子节点的权值异或和为\(x\),那么不同儿子子树中的叶子节点走到该儿子节点的异或和可以不同,所以从儿子连到当前点的边权也可以不一样。
//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 1e5+7;
using LL = int_fast64_t;
int n,depth[MAXN],f[MAXN];
vector<int> G[MAXN];
bool odd = false, even = false;
void dfs(int u, int par){
depth[u] = depth[par] + 1;
bool zero = false;
if(par and G[u].size()==1){
if(depth[u]&1) odd = true;
else even = true;
}
for(int v : G[u]){
if(v==par) continue;
dfs(v,u);
if(f[v]==0) zero = true;
else f[u] += f[v] + 1;
}
if(zero) f[u]++;
}
int main(){
____();
cin >> n;
for(int i = 1; i < n; i++){
int u, v;
cin >> u >> v;
G[u].emplace_back(v);
G[v].emplace_back(u);
}
int root = 1;
for(int i = 1; i <= n; i++) if(G[i].size()>1) root = i;
dfs(root,0);
cout << ((odd and even)?3:1) << ' ' << f[root] << endl;
return 0;
}
\(C.Perfect\ Triples\)
找规律题
对着表找了半天规律没写出来,我菜死了
用四进制表示每一位,可以打表出来
001 002 003
//1行
010 020 030
011 022 033
012 023 031
013 021 032
//1<<2行
100 200 300
101 202 303
102 203 301
103 201 302
110 220 330
111 222 333
112 223 331
113 221 332
... ... ...
//1<<4行
//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
using LL = int_fast64_t;
void solve(){
LL n; cin >> n;
LL m = (n - 1) / 3 + 1, md = n % 3 ? n % 3 : 3, ret = 0, bit = 1, num = 0, a[4];
if(md==1) a[0] = 3, a[1] = 0, a[2] = 1, a[3] = 2;
else if(md==2) a[0] = 1, a[1] = 0, a[2] = 2, a[3] = 3;
else a[0] = 2, a[1] = 0, a[2] = 3, a[3] = 1;
while(true){
if(bit>=m){
ret += (md<<num);
break;
}
m -= bit;
ret += (a[((m-1) / bit + 1) % 4]<<num);
bit <<= 2, num += 2;
}
cout << ret << endl;
}
int main(){
____();
int T;
for(cin >> T; T; T--) solve();
return 0;
}
Codeforces Round #633 (Div. 2)的更多相关文章
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- 【剑指 Offer】07.重建二叉树
题目描述 输入某二叉树的前序遍历和中序遍历的结果,请重建该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字. 示例: 前序遍历 preorder = [3,9,20,15,7] 中序遍历 ...
- 机器学习笔记·adaboost
一.算法简介 Adaboost算法是一种集成算法,所谓集成算法就是将多个弱的分类器组合在一起变成一个强的分类器.弱分类器通常是指分类效果比随机分类稍微好一点的分类器.就像我们在做一个重要决定的时候,通 ...
- 基于 MPI 的快速排序算法的实现
完整代码: #include <iostream> #include <cstdlib> #include <ctime> #include <algorit ...
- 在项目中应该使用Boolean还是使用boolean?
起因 在公司看代码时,看到了使用Boolean对象来完成业务逻辑判断的操作.和我的习惯不一致,于是引起了一些反思. boolean和Boolean的差别咱就不说了,我们仅探讨使用boolean与Boo ...
- CSAPP:Lab0 -Docker搭建纯净Linux环境
1. 安装docker 在mac-os下我们可以利用homebrew很容易的安装docker. brew install docker 当然去官网下载也很容易 Empowering App Devel ...
- linux DRM GPU scheduler 笔记
内核文档: Overview The GPU scheduler provides entities which allow userspace to push jobs into softw ...
- 入门OJ:郭嘉的消息传递
题目描述 我们的郭嘉大大在曹操这过得逍遥自在,但是有一天曹操给了他一个任务,在建邺城内有N(<=1000)个袁绍的奸细 将他们从1到N进行编号,同时他们之间存在一种传递关系,即若C[i,j]=1 ...
- IE浏览器兼容问题总结
IE浏览器兼容问题总结 引自掘金:https://juejin.cn/post/6844903825854185480 一.标准盒模型和怪异盒模型 浏览器的盒子模型分为两类: 标准的W3C盒子模型. ...
- JVM(七)字符串详解
常量池: 我们前面也一直说常量池有三种: 1:class文件中的常量池,前面我们解析class文件的时候解析的就是,这是静态常量池.在硬盘上. 2:运行时常量池.可以通过HSDB查看,是Instan ...
- MySQL主从配置This operation cannot be performed with a running slave io thread; run STOP SLAVE IO_THREAD FOR CHANNEL '' first.
MySQL主从配置This operation cannot be performed with a running slave io thread; run STOP SLAVE IO_THREAD ...