Sheldon Numbers Gym
来源:互联网 发布:淘宝客推广qq空间 编辑:程序博客网 时间:2024/06/05 20:20
题意:A代表N个1,B代表M个0,条件是一个数的二进制满足 ABAB...A 或者 ABAB...AB ,可以不含有B,但至少有一个A,求给定L 和 R之间有多少个满足条件的数字。
思路: 数据的范围是0到2^63次方,对1到63长度的数字进行构造。
注意点: pow返回值要进行强制转换!!!!
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <queue>#include <set>#include <algorithm>#include <stdlib.h>#include <map>#include <math.h>using namespace std;set< unsigned long long> s;int main(){unsigned long long num; for ( int len = 1; len<=64; len++ ) {for ( int a = 1; a<=len ; a++ ) {for ( int b = 0; b<=len-a; b++ ) {string t = ""; num = 0 ; if ( len%(a+b)==0 ) {for ( int i=0; i<len/(a+b); i++ ) {t.append(a,'1'); t.append(b,'0'); }//cout<<"shang"<<endl; }if ( len%(a+b)==a ) {for ( int i=0; i<len/(a+b); i++ ) {t.append(a,'1'); t.append(b,'0'); }t.append(a,'1'); //cout<<"xia"<<endl; }for ( int i=t.length()-1; i>=0; i-- ) num+=(t[i]-'0')*(long long)pow(2,t.length()-i-1); s.insert(num); }}}unsigned long long m,n; cin>>m>>n; unsigned long long cnt = 0; s.erase(0); set<unsigned long long > ::iterator it; for ( it = s.begin(); it!=s.end(); it++ ) {if ( *it>=m && *it<=n ) {++cnt ; } }cout<<cnt<<endl; return 0; }
0 0
- Sheldon Numbers Gym
- Sheldon Numbers Gym
- GYM 101128 H.Sheldon Numbers(枚举)
- Sheldon Numbers
- UVALive 7279 Sheldon Numbers
- Sheldon Numbers 暴力枚举
- UVALive-7279 - Sheldon Numbers【暴力】
- UVALive 7279 Sheldon Numbers 【位运算】【暴力】
- UVALive 7279 Sheldon Numbers(位运算、暴力、想法)
- UVALive 7279 Sheldon Numbers(位运算、暴力)
- Gym - 100338E Numbers 贪心
- Sheldon Cooper
- gym I. Painting the natural numbers
- 【唯一分解定理】Sphenic numbers Gym
- Gym - 100703G-G-Game of numbers-暴力
- 贪心——Playing with numbers ( Gym 101061 E )
- GYM 101102 J.Divisible Numbers(数论+容斥原理)
- GYM 101061 E.Playing with numbers(单调栈)
- 基础篇:3)规范化:3d草绘、建模、装配
- MPI点对点非阻塞式通信
- 游戏编程中的人工智能技术:译者序
- python读取文件夹中的文件
- LeetCode-Easy部分中标签为Math 268. Missing Number
- Sheldon Numbers Gym
- Python实现“维基百科六度分隔理论“之基础爬虫
- 关于myeclipse代码提示
- 正则表达式总结
- 平面上的点——Point类 (I)
- 面试时,你被问到过 TCP/IP 协议吗?
- error LNK2019: 无法解析的外部符号 ******,该符号在函数 _main 中被引用
- Android Studio出现Failed to open zip file问题的解决方法
- 近期工作