hdu5587 BestCoder Round #64 (div.2)
2015-11-28 22:35
323 查看
问题描述
输入描述
输出描述
输入样例
输出样例
Hint
思路:
可以看出1 3 7 15这些特殊的点,于是我们可以利用这些特殊的数反复往前递推
例如 9可以看成先递推前7个数的和,由于是折叠后加一,所以第8个数一定是1,第9个数便是第1个数加1
按照这种规律不停前推即可
Vicky是个热爱数学的魔法师,拥有复制创造的能力。 一开始他拥有一个数列{1}。每过一天,他将他当天的数列复制一遍,放在数列尾,并在两个数列间用0隔开。Vicky想做些改变,于是他将当天新产生的所有数字(包括0)全加1。Vicky现在想考考你,经过100天后,这个数列的前M项和是多少?。
输入描述
输入有多组数据。 第一行包含一个整数T,表示数据组数。T. \left( 1 \leq T \leq 2 * {10}^{3} \right)(1≤T≤2∗103) 每组数据第一行包含一个整数M. \left( 1\leq M \leq {10}^{16} \right)(1≤M≤1016)
输出描述
对于每组数据输出一行答案.
输入样例
3 1 3 5
输出样例
1 4 7
Hint
第一项永远为数字11,因此样例1输出11 第二天先复制一次,用0隔开,得到{1,0,1},再把产生的数字加1,得到{1,1,2},因此样例2输出前3项和1+1+2=41+1+2=4. 第三天先得到{1,1,2,0,1,1,2},然后得到{1,1,2,1,2,2,3},因此样例3输出前5项和1+1+2+1+2=71+1+2+1+2=7
思路:
可以看出1 3 7 15这些特殊的点,于是我们可以利用这些特殊的数反复往前递推
例如 9可以看成先递推前7个数的和,由于是折叠后加一,所以第8个数一定是1,第9个数便是第1个数加1
按照这种规律不停前推即可
#include <iostream> #include <cstring> #include <cstdio> using namespace std; typedef long long ll; #define N 100050 int f ; int a ; ll searc(ll cur) { if(cur == 1) { return 1; } return searc(cur/2)*2+cur/2+1; } int main() { int T; ll n; scanf("%d",&T); while(T--) { scanf("%lld",&n); if(n == 1) { printf("1\n"); continue; } ll from = 1; ll ans = 0; while(from <= n) { from =from*2+1; } from = (from-1)/2; ans += searc(from); ans += n-from; ll t = n-from-1; while(t > 0) { if(t == 1) { ans+=1; break; } from = 1; while(from <= t) { from =from*2+1; } from = (from-1)/2; ans += searc(from); ans += t-from; t = t-from-1; } printf("%lld\n",ans); } }
相关文章推荐
- bzoj2330 糖果 差分约束
- hdu5587 BestCoder Round #64 (div.2)
- el和ognl取pageContext、parameters、request、session、application 等处的属性值
- iOS网络监控— BMReachability
- url-pattern
- HDU 1710
- The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead [duplicate]
- NEUQOJ 1495 田鼠看热闹(Ⅰ)(枚举 + 模拟)
- 神之门V8(2):GC的混乱之治(下)
- CodeForces 600C Make Palindrome 贪心
- 先装windows后装ubuntu,在grub中找不到windows启动的问题
- 四则运算封装
- Swap Nodes in Pairs
- sqldeveloper链接错误 :the account is locked解决办法
- 20151128-04 android四大组件--ContentProvider详解
- Android禁用多点同时触发
- C语言打印水平直方图或者垂直直方图
- sqldeveloper链接错误 :the account is locked解决办法
- H5手机开发锁定表头和首列(惯性滚动)解决方案
- 测试