HDU 5587 Array
来源:互联网 发布:股票预测算法 编辑:程序博客网 时间:2024/06/08 07:09
Array
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 411 Accepted Submission(s): 207
Problem Description
Vicky is a magician who loves math. She has great power in copying and creating.
One day she gets an array {1}。 After that, every day she copies all the numbers in the arrays she has, and puts them into the tail of the array, with a signle '0' to separat.
Vicky wants to make difference. So every number which is made today (include the 0) will be plused by one.
Vicky wonders after 100 days, what is the sum of the first M numbers.
One day she gets an array {1}。 After that, every day she copies all the numbers in the arrays she has, and puts them into the tail of the array, with a signle '0' to separat.
Vicky wants to make difference. So every number which is made today (include the 0) will be plused by one.
Vicky wonders after 100 days, what is the sum of the first M numbers.
Input
There are multiple test cases.
First line contains a single integer T, means the number of test cases.(1≤T≤2∗103)
Next T line contains, each line contains one interger M.(1≤M≤1016)
First line contains a single integer T, means the number of test cases.
Next T line contains, each line contains one interger M.
Output
For each test case,output the answer in a line.
Sample Input
3135
Sample Output
147
Source
BestCoder Round #64 (div.2)
首先先把每一次变化后的字符个数与每一次变化后的和分别存放在a[i], sum[i], 然后搜索前n项,如何a[i] == n 说明这个长度恰好是n,sum[n]就是前n想和,否则就找剩下的部分,由于剩下的部分是a[i]一样,并且每一项+1,所以将这些提取出来,转化成前a[i]个,所以可以用之前的继续搜索
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <vector>#include <map>#include <list>#include <cmath>#include <queue>#include <stack>#include <set>#include <algorithm>#define LL long long#define INF 0x3f3f3f3f#define RR freopen("in.txt","r",stdin)#define WW freopen("out.txt","w",stdout)#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1using namespace std;const LL maxn = 1e16+10;LL a[1010] = {0, 1}, sum[1010] = {0, 1};LL DFS(LL n){ if(n == 0) return 0; int pos; for(int i=1; i<=100; i++) { if(a[i+1] > n) { pos = i; break; } } if(a[pos] == n) return sum[pos]; else return sum[pos] + DFS(n-a[pos]-1) + n - a[pos];}int main(){ for(int i=2; i<=110; i++) { a[i] = a[i-1] * 2 + 1; sum[i] = sum[i-1] * 2 + a[i-1] + 1; if(a[i] > maxn) break; } int T; scanf("%d",&T); while(T--) { LL n; scanf("%lld",&n); printf("%lld\n",DFS(n)); } return 0;}
0 0
- HDU 5587 Array
- HDU 5587(Array-BigInteger)
- HDU 5587:Array
- hdu 5587 Array
- HDU 5587 Array
- HDU 5587 Array
- HDU 5587 Array
- hdu 5587 (Array)
- HDU-5587 Array(DFS)
- HDU 5587 Array (规律)
- HDU 5587 Array(递归)
- hdu 5587 Array(高效)
- HDU 5587 Array 规律+递归
- hdu 6197 array array array
- HDU 6197 array array array
- HDU-Array
- hdu 5587 Array 2015.11.28 bestcoder 1003
- HDU 5587 Array (找规律_二分)
- eclipse导入play项目
- 线程操作范例
- 修改tp-wr841n-v8的flash
- red hat官方的rhel操作系统版本号与内核版本号的对应关系
- Sys.WebForms.PageRequestManager 运行出现Sys未定义错误解决办法
- HDU 5587 Array
- 南大软院大神养成计划第十六天
- 【LeetCode】283Move Zeroes
- C-014.循环嵌套--九九乘法表
- C++文件操作
- Eclipse的中文字体很小
- Michael J. Quinn, 《Parallel Programming in C with MPI and OpenMP》程序代码
- Linux之tcp的结构分析
- 虚拟存储器和cache的异同