Codeforces Round #633(Div.2)

\(A.Filling\ Diamonds\)

答案就是构成的六边形数量+1

  1. //#pragma GCC optimize("O3")
  2. //#pragma comment(linker, "/STACK:1024000000,1024000000")
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
  6. using LL = int_fast64_t;
  7. void solve(){
  8. LL n; cin >> n;
  9. cout << n << endl;
  10. }
  11. int main(){
  12. ____();
  13. int T;
  14. for(cin >> T; T; T--) solve();
  15. return 0;
  16. }

\(B.Sorted\ Adjacent\ Differences\)

考虑排完序之后从中间开始一左一右选择即可

  1. //#pragma GCC optimize("O3")
  2. //#pragma comment(linker, "/STACK:1024000000,1024000000")
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
  6. const int MAXN = 2e5+7;
  7. int n,A[MAXN];
  8. void solve(){
  9. cin >> n;
  10. for(int i = 1; i <= n; i++) cin >> A[i];
  11. sort(A+1,A+1+n);
  12. int mid = n / 2 + 1;
  13. int lp = mid - 1, rp = mid + 1;
  14. cout << A[mid] << ' ';
  15. while(lp!=0 or rp!=n+1){
  16. if(lp!=0) cout << A[lp--] << ' ';
  17. if(rp!=n+1) cout << A[rp++] << ' ';
  18. }
  19. cout << endl;
  20. }
  21. int main(){
  22. ____();
  23. int T;
  24. for(cin >> T; T; T--) solve();
  25. return 0;
  26. }

\(C.Powered\ Addition\)

考虑对于每个数,需要加的最小值为其之前的最大值和这个值的差值,然后找到这个差值的最大值找到其二进制最高位即可

  1. //#pragma GCC optimize("O3")
  2. //#pragma comment(linker, "/STACK:1024000000,1024000000")
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
  6. const int MAXN = 1e5+7;
  7. using LL = int_fast64_t;
  8. int n;
  9. LL A[MAXN];
  10. void solve(){
  11. cin >> n;
  12. for(int i = 1; i <= n; i++) cin >> A[i];
  13. LL minn = 1e10;
  14. LL delta = 0;
  15. for(int i = n; i >= 1; i--){
  16. delta = max(delta,A[i]-minn);
  17. minn = min(A[i],minn);
  18. }
  19. if(!delta) cout << 0 << endl;
  20. else{
  21. while(delta!=(delta&-delta)) delta -= (delta&-delta);
  22. cout << __builtin_ctz(delta)+1 << endl;
  23. }
  24. }
  25. int main(){
  26. ____();
  27. int T;
  28. for(cin >> T; T; T--) solve();
  29. return 0;
  30. }

\(D.Edge\ Weight\ Assignment\)

考虑最少不同的数,各个叶子节点到根的距离的奇偶性如果一样,那么所有边权都可以相等,否则的话用\(1,2,3\)三个数来赋值边权必然可以满足条件

对于最多的不同的数,考虑树形\(DP\),\(dp[i]\)表示以\(i\)为根的子树所用的最多的不同边权,以非叶节点为根进行\(dfs\),考虑转移,对于\(u\)点的所有儿子,如果存在叶子节点的话,\(dp[u]+=1\),叶子节点连上来的边权必然相等,对于儿子中的非叶子节点\(v\),转移为\(dp[u] += dp[v] + 1\),可以假设叶子节点走到儿子节点的权值异或和为\(x\),那么不同儿子子树中的叶子节点走到该儿子节点的异或和可以不同,所以从儿子连到当前点的边权也可以不一样。

  1. //#pragma GCC optimize("O3")
  2. //#pragma comment(linker, "/STACK:1024000000,1024000000")
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
  6. const int MAXN = 1e5+7;
  7. using LL = int_fast64_t;
  8. int n,depth[MAXN],f[MAXN];
  9. vector<int> G[MAXN];
  10. bool odd = false, even = false;
  11. void dfs(int u, int par){
  12. depth[u] = depth[par] + 1;
  13. bool zero = false;
  14. if(par and G[u].size()==1){
  15. if(depth[u]&1) odd = true;
  16. else even = true;
  17. }
  18. for(int v : G[u]){
  19. if(v==par) continue;
  20. dfs(v,u);
  21. if(f[v]==0) zero = true;
  22. else f[u] += f[v] + 1;
  23. }
  24. if(zero) f[u]++;
  25. }
  26. int main(){
  27. ____();
  28. cin >> n;
  29. for(int i = 1; i < n; i++){
  30. int u, v;
  31. cin >> u >> v;
  32. G[u].emplace_back(v);
  33. G[v].emplace_back(u);
  34. }
  35. int root = 1;
  36. for(int i = 1; i <= n; i++) if(G[i].size()>1) root = i;
  37. dfs(root,0);
  38. cout << ((odd and even)?3:1) << ' ' << f[root] << endl;
  39. return 0;
  40. }

\(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行

  1. //#pragma GCC optimize("O3")
  2. //#pragma comment(linker, "/STACK:1024000000,1024000000")
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
  6. using LL = int_fast64_t;
  7. void solve(){
  8. LL n; cin >> n;
  9. LL m = (n - 1) / 3 + 1, md = n % 3 ? n % 3 : 3, ret = 0, bit = 1, num = 0, a[4];
  10. if(md==1) a[0] = 3, a[1] = 0, a[2] = 1, a[3] = 2;
  11. else if(md==2) a[0] = 1, a[1] = 0, a[2] = 2, a[3] = 3;
  12. else a[0] = 2, a[1] = 0, a[2] = 3, a[3] = 1;
  13. while(true){
  14. if(bit>=m){
  15. ret += (md<<num);
  16. break;
  17. }
  18. m -= bit;
  19. ret += (a[((m-1) / bit + 1) % 4]<<num);
  20. bit <<= 2, num += 2;
  21. }
  22. cout << ret << endl;
  23. }
  24. int main(){
  25. ____();
  26. int T;
  27. for(cin >> T; T; T--) solve();
  28. return 0;
  29. }

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. 讲讲Java8的Optional类

    前言 Java 8中引入了 Optional 类来解决 NullPointerException 与繁琐的 null 检查,该类首次出现在 Guava.Java 8 才成为类库中的一部分. 入门 Op ...

  2. HP Proliant DL580 gen9 阵列卡P440AR 高速缓存 被禁用

    摘录内容: IMPORTANT: This issue does NOT occur when the operating system shuts down gracefully. In addit ...

  3. Linux下安装svn教程

    前言 最近买了新服务器,准备开始弄一些个人的开源项目.有了服务器当然是搞一波svn啦.方便自己的资料上传和下载.于是在此记录搭建svn的方式,方便以后直接使用. 安装 使用yum源进行安装,十分的方便 ...

  4. Laya 断点调试

    Laya 打断点调试并查看堆栈的方法 发现直接加断点不行没办法调试,直接使用这中方法好像可以,选择F5调试 var camera =this.GameScene.getChildByName(&quo ...

  5. Netty与NIO

    初识Netty Netty是由JBoss提供的一个Java的开源框架,是GitHub上的独立项目. Netty是一个异步的,基于事件驱动的网络应用框架,用于快速开发高性能.高可靠的网络IO程序. Ne ...

  6. C++ 中的 inline 详解

    inline:是一个关键词,放在一个函数前面,说明这个函数是inline函数. inline函数是什么?inline有什么作用? 为了解答这个问题,我们首先要知道编译器是如何为我们工作的. 先看一段代 ...

  7. Java并发包源码学习系列:详解Condition条件队列、signal和await

    目录 Condition接口 AQS条件变量的支持之ConditionObject内部类 回顾AQS中的Node void await() 添加到条件队列 Node addConditionWaite ...

  8. PAT Advanced 1003 Emergency 详解

    题目与翻译 1003 Emergency 紧急情况 (25分) As an emergency rescue team leader of a city, you are given a specia ...

  9. 浅入深出了解XXE漏洞

    环境搭建 https://github.com/c0ny1/xxe-lab 为了更深入的理解,我准备理论和实际相结合的了解XXE! 浅谈XML 初识XML 一个好的代码基础能帮助你更好理解一类漏洞,所 ...

  10. 通过SE14重建数据库表

    通过程序中的SQL语句向数据库表中插入的内容,系统无法转换,并且已经存在于数据库表中,那么当对该表进行保存数据的修改时,可能会导致该表从数据库中的删除. 举了例子:(完全是为了方便理解) SAP系统, ...