HDU 6121 Build a tree(找规律+模拟)】的更多相关文章

Build a tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 946    Accepted Submission(s): 369 Problem Description HazelFan wants to build a rooted tree. The tree has n nodes labeled 0 to n−1…
http://acm.hdu.edu.cn/showproblem.php?pid=6121 题意:给你一颗完全K叉树,求出每棵子树的节点个数的异或和. 思路: 首先需要了解一些关于完全K叉树或满K叉树的一些知识: 对于每棵子树,只有三种情况: ①是满K叉树  ②不是满K叉树  ③叶子节点 并且非满K叉树最多只有一个,所以只需要将它进行特殊处理,具体看代码吧,说不清楚.代码参考了http://blog.csdn.net/my_sunshine26/article/details/77200282…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6121 题意:一个n个点的完全k叉树,求每个节点的size的异或和. 解法:容易发现,考虑根的所有孩子,最多只有一个不是满k叉树,我们只要把这个子节点作为临界点,其左边的就是满k叉树,其右边的便是比左边层数小一的满k叉树,那么我们每次只要算出中间这个非满k叉树的节点个数即可,然后对这个孩子进行递归处理.而其他子树由于是满k叉树,其数量可以提前预处理出来.这样处理在k>2的时候复杂度是logk(n)的,…
http://acm.hdu.edu.cn/showproblem.php?pid=6121 题目大意: 给你一颗 n 个节点的完全 k 叉树,问你这棵树中所有子树结点个数的总异或值. 分析: 我们很容易看到于发现对于这样的一颗树 , 肯定是只有一颗子树不是满k叉树 , 知道这样后 , 这就很简单了: 我们可以找到不满的树的编号P , 那左边就要(P-1)棵满树 , 右边有(n-P)棵少一层的满树 , 我们在分析,如果左边的树的数量是偶数 , 那我们可以不用计算 , 奇数只要计算一颗:右边同样的…
题目链接 Problem Description HazelFan wants to build a rooted tree. The tree has n nodes labeled 0 to n−1, and the father of the node labeled i is the node labeled ⌊i−1k⌋. HazelFan wonders the size of every subtree, and you just need to tell him the XOR…
HazelFan wants to build a rooted tree. The tree has nn nodes labeled 0 to n−1, and the father of the node labeled i is the node labeled  . HazelFan wonders the size of every subtree, and you just need to tell him the XOR value of these answers. Input…
/** * 题意:一棵 n 个点的完全 k 叉树,结点标号从 0 到 n - 1,求以每一棵子树的大小的异或和. * 解法:k叉树,当k=1时,特判,用xorn函数,具体解释:http://blog.csdn.net/a3630623/article/details/12371727 * k不等一1:我们dfs求解,当是满k叉树,可以很快求的:每层最对可能三类树,少一层的满k叉树, * 少两层的满k叉树,不满的子树dfs求解. */ #include <cstdio> #include <…
普通NIM规则加上一条可以分解为两堆,标准的Multi-SG游戏 一般Multi-SG就是根据拓扑图计算SG函数,这题打表后还能发现规律 sg(1)=1 sg(2)=2 sg(3)=mex{0,1,2,1^2}=4 sg(4)=mex{0,1,2,sg(3)}=3 可以发现3和4的时候相当于互换了位置 /** @Date : 2017-10-12 21:20:21 * @FileName: HDU 3032 博弈 SG函数找规律.cpp * @Platform: Windows * @Autho…
题目描述 现代数学的著名证明之一是Georg Cantor证明了有理数是可枚举的.他是用下面这一张表来证明这一命题的: 1/1 1/2 1/3 1/4 1/5 … 2/1 2/2 2/3 2/4 … 3/1 3/2 3/3 … 4/1 4/2 … 5/1 … … 我们以Z字形给上表的每一项编号.第一项是1/1,然后是1/2,2/1,3/1,2/2,… 输入输出格式 输入格式: 整数N(1≤N≤10000000) 输出格式: 表中的第N项 输入输出样例 输入样例#1: 复制 7 输出样例#1: 复…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1030 Delta-wave Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7163    Accepted Submission(s): 2772 Problem Description A triangle field is numbe…
已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这题输出二进制数就行了......那就更简单了,直接输出1,然后后面跟n-1个0就行了╮(╯_╰)╭ 下面AC代码 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm>…
Problem about GCD Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 470    Accepted Submission(s): 77 Problem Description Given integer m. Find multiplication of all 1<=a<=m such gcd(a, m)=1 (cop…
题目 //找规律,123321123321123321…发现这样排列恰好可以错开 // 其中注意题中数据范围: M是行,N是列,3 <= N < 2×M //则猜测:m,m,m-1,m-1,m-2,m-2,……,2,2,1,1求出前m个数字的和就是答案. //发现案例符合(之前的代码第二天发现案例都跑不对,真不知道我当时眼睛怎么了) #include <iostream> #include<stdio.h> #include<string.h> #inclu…
主要还是找规律,然后大数相乘 #include<stdio.h> #include<string.h> #include<math.h> #include<time.h> #include<map> #include<iostream> #include<ctype.h> #include<string> #include<algorithm> #include<stdlib.h> #i…
A Boring Question Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 865    Accepted Submission(s): 534 Problem Description There are an equation.∑0≤k1,k2,⋯km≤n∏1⩽j<m(kj+1kj)%1000000007=?We define…
Starting from point (0,0) on a plane, we have written all non-negative integers 0, 1, 2,... as shown in the figure. For example, 1, 2, and 3 has been written at points (1,1), (2,0), and (3, 1) respectively and this pattern has continued. You are to w…
M=1:aaaaaaaa…… M=2:DFS+manacher, 暴出N=1~25的最优解,找规律.N<=8的时候直接输出,N>8时,头两个字母一定是aa,剩下的以aababb循环,最后剩余<5全部补a,等于5补aabab. M=3:abcabcabcabc…… #include <cstdio> #include <cstring> using namespace std; const char str[] = "aababb"; int m…
题意:问是否能把MI通过以下规则转换成给定的字符串s. 1.使M之后的任何字符串加倍(即,将Mx更改为Mxx). 例如:MIU到MIUIU.2.用U替换任何III.例如:MUIIIU至MUUU.3.去掉任何UU. 例如:MUUU到MU. 分析: 1.MI的变换首先要复制I,可以复制为1,2,4,8,16,32,……(2的n次方)个. 2.由于可以用U替换任何III,所以将字符串s中所有的U变为I后,统计I的个数cnt. 3.由于可以去掉任何UU,所以转换成功必须满足cnt+6x==2的n次方.…
If we sum up every digit of a number and the result can be exactly divided by 10, we say this number is a good number. You are required to count the number of good numbers in the range from A to B, inclusive. InputThe first line has a number T (T <=…
应该不算太水吧. 17  24   1   8  15   23   5   7  14  16    4   6  13  20  22   10  12  19  21   3   11  18  25   2   9 对于上面的数据,根据题目中的提示,很容易就看到对角线上的数字是11.12.13.14.15.其他的数据,比如说2,从2往右上查就是2.3.4.5.1.描述起来好像很麻烦,但是对着图看一下就可以很容易看明白. 接下来继续观察数据,我们可以看出在第一行实际上是从1开始往右查每个数…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5976 Detachment Time Limit: 4000/2000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others) 问题描述 In a highly developed alien society, the habitats are almost infinite dimensional space. In the histo…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5754 给你四种棋子,棋子一开始在(1,1)点,两个人B和G轮流按每种棋子的规则挪动棋子,棋子只能往右下方移动,谁最后先挪动棋子到(n,m)位置,谁就胜利.要是两个人都不可能赢,就输出D. king的情况在纸上模拟了一下,感觉就是当n*m为奇数时先手输,否则就赢. rook的情况比较简单,相当于在两堆石子中取石子,只能在一堆中取.当n等于m时,先手必败,因为先手怎么取,后手都会跟上取 使得两堆石子相同…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4662 题意: 初始字符串为"MI". 有三个操作: (1)将'M'之后的所有字符翻倍.For example: MIU to MIUIU. (2)将'III'变为一个'U'.For example: MUIIIU to MUUU. (3)删除'UU'.For example: MUUU to MU 给你一个字符串s,问你是否能将初始字符串"MI"通过一系列操作变为s.…
题目链接 :http://acm.hdu.edu.cn/showproblem.php?pid=6030 Problem Description Little Q wants to buy a necklace for his girlfriend. Necklaces are single strings composed of multiple red and blue beads. Little Q desperately wants to impress his girlfriend,…
题目链接 Problem Description Consider the aggregate An= { 1, 2, -, n }. For example, A1={1}, A3={1,2,3}. A subset sequence is defined as a array of a non-empty subset. Sort all the subset sequece of An in lexicography order. Your task is to find the m-th…
题目链接 Problem Description There is a nonnegative integer sequence a1...n of length n. HazelFan wants to do a type of transformation called prefix-XOR, which means a1...n changes into b1...n, where bi equals to the XOR value of a1,...,ai. He will repea…
题目链接 Problem Description Function Fx,ysatisfies: For given integers N and M,calculate Fm,1 modulo 1e9+7. Input There is one integer T in the first line. The next T lines,each line includes two integers N and M . 1<=T<=10000,1<=N,M<2^63. Output…
对于和规律或者数学有关的题真的束手无策啊QAQ 首先发现两个性质: 1.不管中间怎么碰撞,所有蚂蚁的相对位置不会改变,即后面的蚂蚁不会超过前面的蚂蚁或者落后更后面的蚂蚁. 2.因为所有蚂蚁速度一样,不管标号的话两只蚂蚁的碰撞相当于直接互相穿过,所以最初有多少蚂蚁方向向左,最后就有多少蚂蚁从左落下,向右同理. 总结一下又可以发现,比如有$cntl$只蚂蚁最初向左,$cntr$只蚂蚁最初向右,那么最后就是原位置的左边连续$cntl$只从左落下,原位置右边连续$cntr$只从右落下.我们将所有方向向左…
Vasya has a string s of length n. He decides to make the following modification to the string: Pick an integer k, (1≤k≤n). For i from 1 to n−k+1, reverse the substring s[i:i+k−1] of s. For example, if string s is qwer and k=2, below is the series of…
\(给你一个nnn个结点的完全有向图,求其字典序最小的欧拉回路,输出lll到rrr之间的结点为多少.\) 模拟一下n=5的时候 开始肯定是1-2-1-3-1-4-1-5 注意这个时候不能再从5到1,否则无路可走.那么5出发贪心就是 2-3-2-4-2-5 其实规律已经出来了,剩下就靠模拟了. 1 2 1 3 1 4 1 5 - 1 n 2 3 2 4 2 5 - 2 n 3 4 3 5 3 6 - 3 n - 1 #include <bits/stdc++.h> using namespace…