【PTA】1049 Counting Ones】的更多相关文章

[算法]DP [题解]开long long…… #include<cstdio> #include<algorithm> #include<cstring> using namespace std; ; int a[maxn],n; int main() { scanf("%d",&n); ,ans=,x; ;i<=n;i++) { scanf("%lld",&x); sum+=x; ans=max(ans,…
[题目链接] 点击打开链接 [算法] 离散化 + dfs + 树状数组 [代码] #include<bits/stdc++.h> using namespace std; #define MAXN 100000 int N,i,lth,x,pos; ],tmp[MAXN+],rank[MAXN+],ans[MAXN+]; vector<]; template <typename T> inline void read(T &x) { ; x = ; char c =…
题意: 输入一个正整数N(N<=2^30),输出从1到N共有多少个数字包括1. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin>>n; ; ,r=,low_bit=,yushu…
问题:http://hihocoder.com/problemset/problem/1049?sid=767510 已知一棵二叉树的前序遍历及中序遍历结果,求后序遍历结果 思路: 前序:根-左子树-右子树 中序:左子树-根-右子树 后序:左子树-右子树-根 递归的方法,从前序得到根结点,然后根据中序发现两个子树.先求子树的后序遍历结果,再把当前的根添加在最后即可. #include <iostream> #include <string> using namespace std;…
Counting Bits Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array. Example:For num = 5 you should return [0,1,1,2,1,2]. Follow up…
http://www.lydsy.com/JudgeOnline/problem.php?id=1049 题意:给一个长度为n的整数序列.把它变成一个单调严格上升的序列.但是不希望改变过多的数,也不希望改变的幅度太大.1. 询问最少需要改变多少个数. 2. 在1的条件下每个数改变的绝对值之和的最小值.(n<=35000, 数据随机) #include <cstdio> #include <cstring> #include <cmath> #include <…
http://www.wikioi.com/problem/1049/ 这题我之前写没想到迭代加深,看了题解,然后学习了这种搜索(之前我写的某题也用过,,但是不懂专业名词 囧.) 迭代加深搜索就是限制搜索深度,一旦有可行解立即跳出,优化了深搜一直搜下去的毛病. (囧,这题搜索题写了我一下午,我搜索的确很弱啊!!!) 第一次写出来的版本我没有注意到,应该是从多个点拓展下去,而不是从某个点. 第二次写出来的版本的确从所有可行点拓展下去,但是样例都tle.. 第三次看了别人的标程发现直接向右和向拓展就…
题目描述 The cows have once again tried to form a startup company, failing to remember from past experience that cows make terrible managers! The cows, conveniently numbered  (), organize the company as a tree, with cow 1 as the president (the root of th…
题目描述 定义 \(d(n)\) 为 \(n\) 的正因数的个数,比如 \(d(2) = 2, d(6) = 4\). 令 $ S_1(n) = \sum_{i=1}^n d(i) $ 给定 \(n\),求 \(S_1(n)\). 输入格式 第一行包含一个正整数 \(T\) (\(T \leq 10^5\)),表示数据组数. 接下来的 \(T\) 行,每行包含一个正整数 \(n\) (\(n < 2^{63}\)). 输出格式 对于每个 \(n\),输出一行一个整数,表示 \(S_1(n)\)…
传送门 Description 把1……n这n个数中任取3个数,求能组成一个三角形的方案个数 Input 多组数据,对于每组数据,包括: 一行一个数i,代表前i个数. 输入结束标识为i<3. Output 对于每组数据,输出: 对应的方案个数 Sample Input Sample Output Hint n≤1e6. 三个数字x,y,z能组成三角形当且仅当对于任意顺序,都满足x+y>z. Solution 考虑把所有能组成的三角形按照最长边分类.因为三边长度互不相同,所以每个三角形都会被唯一…