ACdream 1154 Lowbit Sum(数学:推理)
来源:互联网 发布:php 图片字节流 编辑:程序博客网 时间:2024/05/20 02:27
Lowbit Sum
Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others)
SubmitStatisticNext Problem
Problem Description
long long ans = 0;
for(int i = 1; i <= n; i ++)
ans += lowbit(i)
lowbit(i)的意思是将i转化成二进制数之后,只保留最低位的1及其后面的0,截断前面的内容,然后再转成10进制数
比如lowbit(7),7的二进制位是111,lowbit(7) = 1
6 = 110(2),lowbit(6) = 2,同理lowbit(4) = 4,lowbit(12) = 4,lowbit(2) = 2,lowbit(8) = 8
每输入一个n,求ans
Input
多组数据,每组数据一个n(1 <= n <= 10^9)
Output
每组数据输出一行,对应的ans
Sample Input
123
Sample Output
134
Source
dream
Manager
scaucontest
SubmitStatistic
明明是一道很水的题...AC率都接近50%了
我想了好久才想出来
感觉也是因为刷网页刷的不在状态了
以后群赛等挂完了再做...不然全忙着刷网页了
给定一个n
考虑n二进制位从最低位到最高位依次为1的情况
代码如下:
#include <cstdio>#include <cstdlib>#include <bitset>#include <iostream>#include <algorithm>#define LL long longusing namespace std;LL n;int main(void) { while(cin >> n) { LL i = 4; LL tmp = (n+1)/2; while((n+i/2)/2 > 0) { tmp += ((n+i/2)/i)*(i/2); i *= 2; } cout << tmp << endl; }}
0 0
- ACdream 1154 Lowbit Sum(数学:推理)
- ACdream 1154 Lowbit Sum
- ACdream OJ 1154 Lowbit Sum
- 数位DP ACdream 1154 Lowbit Sum
- ACdream 1154 Lowbit Sum (数位DP)
- ACdream 1154 Lowbit Sum(数位DP)
- ACdream 1154 Lowbit Sum (数位dp)
- ACdream 1148 GCD SUM(数学:推理+数论:莫比乌斯函数)
- Lowbit Sum
- Lowbit Sum
- ACdreamOJ 1154 Lowbit Sum (数位dp)
- ACdream: Sum
- lowbit
- lowbit
- lowbit
- lowbit
- lowbit
- lowbit
- hdu a strang lift
- cocosbuilder源码编译
- hd 2070 Fibbonacci Number
- hdoj -2603 Bone Collector
- ny 13 斐波那契额数列
- ACdream 1154 Lowbit Sum(数学:推理)
- 社会心理学(一)
- 详细解析C语言中的sizeof
- HDU2159:FATE(二维完全背包)
- rild
- Eclipse搭建android环境
- Orders——字符串
- oracle11g导出空表
- Latex 模板