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)的更多相关文章

  1. 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 ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  9. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

随机推荐

  1. 串的模式匹配算法1 BF算法

    BF算法 字符串的模式匹配不一定要从主串的第一个位置开始,可以指定主串中查找的起始位置 pos. 2. 算法步骤: 1)分别利用计数器指针 i 和 j 指定主串和模式串即小字符串待比较的位置,初始化为 ...

  2. python函数1-函数基础

  3. Xshell与Xftp免费下载安装及步骤

    Xshell与Xftp免费下载安装及步骤 1.进入Xshell的官网:https://www.netsarang.com/zh/ 加粗样式 2.选择你需要的软件进行下载如:Xshell 3.选择家庭和 ...

  4. openpose c++ 配置教程 + python api

    之前有介绍过基于tensorflow的openpose版本安装,但是我觉得没有caffe框架那么好用,很多功能也实现不了,比如调节net_resolution的调节,通过调节分辨率来提高检测的精确性和 ...

  5. SAP client锁定

    今天发现一个函数可以锁定SAP CLIENT . SCCR_LOCK_CLIENT 参数是client号码. 还可以通过事物SU10批量锁定用户登陆client

  6. RocketMQ在linx安装及其有关问题解决

    Linx安装和使用: rocketmq官网:http://rocketmq.apache.org/ 首先安装JDK(推荐使用JDK1.8),并配置环境变量 下载rocketmq压碎包并解压到指定目录 ...

  7. C#从入门到放弃治疗一:初探C#世界

    C#是一款高级的面向对象语言,运行于.NET framework之上的高级程序设计语言.其语言规范和,语法和java有着惊人的类似之处.所以如果你在学习C#之前有着java的基础,你将快速地入门.当然 ...

  8. 学习Java第三天

    方法重载:同一个类,方法名相同,参数不同(个数不同,类型不同,顺序不同),判断是否重载,只看方法名和参数,跟返回值无关. IDEA查看方法源代码:Crtl + 鼠标左键 进制表示 Java数值默认为十 ...

  9. .net core 不同地区时间相互转换

    .net core 不同地区时间相互转换 //韩国时间转换成当前时间 //value=需要转换的时间 //Korea Standard Tim 韩国时间 //China Standard Time 中 ...

  10. vfd-cloud——一个适合练习上手的云存储网盘springboot项目(开发中)

    vfd-cloud           ​ 一个基于SpringBoot的云存储网盘项目,适合练手学习SpringBoot,用到的技术栈列到了下面.支持用户的注册登陆及修改密码,利用邮箱进行验证.支持 ...