UVA11645:Bits
2015-06-15 15:35
453 查看
题意:
求1~n的二进制中连续出现的两个1有多少个
思路:
首先枚举两个1的位置,如果此时枚举的位置与元素一样,则还要多加
求1~n的二进制中连续出现的两个1有多少个
思路:
首先枚举两个1的位置,如果此时枚举的位置与元素一样,则还要多加
#include <iostream> #include <stdio.h> #include <string.h> #include <string> #include <stack> #include <queue> #include <map> #include <set> #include <vector> #include <math.h> #include <bitset> #include <list> #include <algorithm> #include <climits> using namespace std; #define lson 2*i #define rson 2*i+1 #define LS l,mid,lson #define RS mid+1,r,rson #define UP(i,x,y) for(i=x;i<=y;i++) #define DOWN(i,x,y) for(i=x;i>=y;i--) #define MEM(a,x) memset(a,x,sizeof(a)) #define W(a) while(a) #define gcd(a,b) __gcd(a,b) #define LL long long #define N 100005 const LL MOD = 1e13; #define INF 0x3f3f3f3f #define EXP 1e-8 #define lowbit(x) (x&-x) LL a,b; void add(LL x) { b+=x; a+=b/MOD; b%=MOD; } int main() { LL cas = 1,n; while(scanf("%lld",&n),n>=0) { LL m = 1,t=n; a = b = 0; while(n) { add((n>>2)*m); if((n&3)==3) add((t&(m-1))+1); m<<=1; n>>=1; } printf("Case %lld: ",cas++); if(a) printf("%lld%013lld\n",a,b); else printf("%lld\n",b); } return 0; }
相关文章推荐
- 【Java安全技术探索之路系列:Java可扩展安全架构】之三:JCA(二):JCA类和接口
- 【Java安全技术探索之路系列:Java可扩展安全架构】之二:JCA(一):JCA架构介绍
- 为什么整个互联网行业都缺前端工程师?
- java 泛型的几点备忘
- Sublime Text3注册码 (备用)
- my ibatis学习
- svn常用命令行和批处理 WIN
- 直接路由模式(LVS-DR)
- ZOJ 1091 Knight Moves
- JSP(4)----servlet编程2
- Linux下使用Google Authenticator配置SSH登录动态验证码
- 海量数据处理算法—Bloom Filter
- 浅谈协方差矩阵
- 查看Linux内核版本的命令
- Django 安装 在CentOS
- Java GC
- 华为2014第三题
- 浅谈协方差矩阵
- 对hive和hbase的理解 基于【浅谈Hive vs. HBase】
- 第三章 动态规划