UVA11645:Bits
来源:互联网 发布:怎样在淘宝客服发图片 编辑:程序博客网 时间:2024/05/02 01:56
题意:
求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 100005const 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;}
1 0
- UVA11645:Bits
- uva11645 Bits(数位统计)
- UVA11645 Bits【位运算+大数】
- uva11645 - Bits 统计 巧妙的大数
- uva11645
- UVa11645
- Bits
- Bits*
- UVA_446_Kibbles "n" Bits "n" Bits "n" Bits
- Persistent Bits
- Changing Bits
- leetcode_num190_Reverse Bits
- Reverse Bits
- Reverse Bits
- Reverse Bits
- Reverse Bits
- Reverse Bits
- Reverse Bits
- cocos2d-x进度条CCProgressTimer详解
- Android资源篇
- 钢筋连接套筒厂家
- 返回键的监听
- chkconfig命令
- UVA11645:Bits
- 数据实验结构(二)——栈和队列的设计与实现
- java 慎用ArrayList的contains方法,使用HashSet的contains方法代替
- Openfire + Smack 4.1.1 搭建Android聊天平台
- 多继承原理抛砖 - 虚继承的应用场景 - 虚继承能解决的问题有限
- 如果像招聘程序员那样招聘木匠
- Android ViewDragHelper 实现 QQ5.0 侧滑
- androidの监听EditView中的文本TextWatcher
- 位运算