hdu 6121(Build a tree) 瞎搞+麻烦
来源:互联网 发布:qq游戏网络异常 编辑:程序博客网 时间:2024/06/09 17:25
题目链接:点击打开链接
题目大意:给定一棵有n个结点的k叉树,求所有子树的大小的异或和~~~
多校补题日记~~~
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <cmath>using namespace std;typedef long long llt;llt SIZE[100];llt L[100];//完全k叉树llt complete(llt n,int depth,int k){ if((k&1)==0) return n; else { llt ans=0; for(int i=1;i<=depth;i++) ans^=SIZE[i]; return ans; }}//不平衡的k叉树llt dfs(llt n,int depth,int k){ llt ret=n; llt rem=n-SIZE[depth]; if(rem%L[depth]==0) { llt comp=rem/L[depth]; if(comp&1) ret^=complete(SIZE[depth],depth,k); if((k-comp)&1) ret^=complete(SIZE[depth-1],depth-1,k); return ret; } else { llt comp=rem/L[depth]; llt cut=rem%L[depth]; if(comp&1) ret^=complete(SIZE[depth],depth,k); if((k-comp-1)&1) ret^=complete(SIZE[depth-1],depth-1,k); return ret^dfs(SIZE[depth-1]+cut,depth-1,k); }}int main(){ int t; scanf("%d",&t); while(t--) { llt n,k; scanf("%lld%lld",&n,&k); if(k==1) { if(n%4==1) printf("%d\n",1); else if(n%4==2) printf("%d\n",n+1); else if(n%4==3) printf("%d\n",0); else printf("%d\n",n); continue; } int depth=1; llt sum=1,left=k; L[1]=1; while(sum+left<=n) { SIZE[depth]=sum; L[++depth]=left; sum+=left;left*=k; } SIZE[depth]=sum; if(sum==n) printf("%lld\n",complete(n,depth,k)); else printf("%lld\n",dfs(n,depth,k)); } return 0;}
阅读全文
0 0
- hdu 6121(Build a tree) 瞎搞+麻烦
- HDU 6121 Build a tree
- hdu 6121 Build a tree
- hdu 6121 Build a tree
- HDU 6121Build a tree
- hdu--6121--Build a tree
- hdu--6121:Build a tree
- hdu 6121 Build a tree
- HDU-6121 Build a tree
- hdu 6121 Build a tree
- HDU 6121 Build a tree【】
- HDU 6121 Build a tree [想法题]
- HDU 6121 Build a tree [想法题]
- hdu 6121 Build a tree (模拟)
- HDU 6121 Build a tree (技巧)
- hdu 6121 Build a tree (图论)
- HDU 6121 Build a tree(递归)
- HDU 4925 Apple Tree (瞎搞)
- Webpack3的使用(一)
- NOIP2017 D1T2 时间复杂度
- 数值的整数次方
- linux一些比较常用的命令
- 案例解决:一次oracle掉电的处理过程[转]
- hdu 6121(Build a tree) 瞎搞+麻烦
- redis ae.c/acMain()
- JMS(一)--JMS基本概念
- IDEA spring boot+jsp 404
- Thread 匿名内部类
- jetty 6.x https访问双向认证配置方法
- 科林明伦杯哈尔滨理工大学第七届程序设计团队赛-Aggie’s Tasks
- github使用问题记录及解决办法
- Android adapter.notifyDataSetChanged失效的可能原因