input n 1<=n<=1e18 output 有n个结点的满二叉树有多少个不相同结点数的子树 做法:树有h=log2(n)层,最多有2h-2种(1除外),然后再n减去u重复的即可 #include <bits/stdc++.h> #include <cstdio> #include <queue> #include <cstring> #include <iostream> #include <cstdlib> #i…
Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2086 ——每天在线,欢迎留言谈论. 题目大意: 有如下方程:Ai = (Ai-1 + Ai+1)/2 - Ci (i = 1, 2, 3, .... n). 若给出A0, An+1, 和 C1, C2, .....Cn. 求 A1 . 思路: 多写几个例子,找规律推导(抄的). 感想: 老啦,老啦,不行了. Java AC代码: import java.util.Scanner;…
http://acm.hdu.edu.cn/showproblem.php?pid=5047 找规律 信kuangbin,能AC #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map&g…
input T 1<=T<=100 n k 1<=n<=1e9  n<=2^k<=2^60 output 从1走到第k层,下一层的数是上一层的数×2或者×2+1,每次加上或者减去走过的数得到n 输出每行输出这一层的数,再输出加还是减 做法:可以发现每次都往×2走时e可以得到<2^k的所有奇数,然后a将最后一个改为2^k+1就可以在原来的基础上得到所有偶数 如用1,2,4,8通过加减可以得到-1,1,-3,3,-5,5,-7,7,然后1,2,4,9通过加减就可以得到…
http://acm.hdu.edu.cn/showproblem.php?pid=5106 给定n和r,要求算出[0,r)之间所有n-onebit数的和,n-onebit数是所有数位中1的个数. 对于一个n-bit数,可以根据与R最高不同位的位置分成几类.比如R=100100010,可以分成0xxxxxxxx,1000xxxxx,10010000x三类.x处可任取0或者1.x的个数为n,x中1的个数为k.和分两部分,高于n位的有C(n,k)乘以n位之前的数字,低于n位的部分有C(n-1,k-1…
题目意思很简单. 就是洗牌,抽出奇数和偶数,要么奇数放前面,要么偶数放前面. 总共2^N张牌. 需要问的是,给了A X B Y  问经过若干洗牌后,第A个位置是X,第B个位置是Y 是不是可能的. Jason is not only an ACMer, but also a poker nerd. He is able to do a perfect shuffle. In a perfect shuffle, the deck containing K cards, where K is an…
 题目链接: D - Doom  HDU - 5239  题目大意:首先是T组测试样例,然后n个数,m次询问,然后每一次询问给你一个区间,问你这个这段区间的加上上一次的和是多少,查询完之后,这段区间里面的每个数变为原来的平方. 具体思路:这个模数,和正常的模数不一样. 然后通过打表能发现,每个数不断自身平方对p取模后经过有限次 就不会变化了, 测试少于30次 所以也就是说每个节点至多会被更新30次. 注意会爆long long ,需要用unsigned long long . AC代码: #in…
Description In computer science, a binary tree is a tree data structure in which each node has at most two children. Consider an infinite full binary tree (each node has two children except the leaf nodes) defined as follows. For a node labelled v it…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4708 思路:由于N不大,并且我们可以发现通过旋转得到的4个对角线的点的位置关系,以及所要旋转的最小步数,然后把所有的符合条件的都加入数组中,最后排序即得. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; struct No…
题意: 给出矩阵M,求M*M矩阵的r行c列的数,每个查询跟前一个查询的结果有关. 解法: 观察该矩阵得知,令ans = M*M,则 ans[x][y] = (n-1-x行的每个值)*(n-1+y列的每个值).直接对每个查询做n次累加(n*m=10^8的复杂度)竟然可以水过. 官方题解给的是n^2的算法,维护一个前缀和,即sum[i][j] 表示 i+j不变的所有sum[i][j]之和. 因为 ans[x][y]就是 a[y]*a[2*n-x] + .... + a[y+n-1]*a[n-x+1]…