题意

给你两个整数X和Y

问你在区间[X,Y]中,有多少数字的二进制满足ABAB或者A这种形式。A是某个数量的1,B是某个数量的0。

分析

因为数据规模很大,直接枚举x和y之间的数字然后判断会超时。所以直接构造符合的二进制串然后判断是不是在区间[X,Y]内就好。因为二进制串的长度最多只有63,所以随便枚举就行。但是写起来确实麻烦,容易出错的地方太多。

下面的代码是在场上两个队友写的,场上的代码嘛~可能有点乱~(好吧是我懒得再写一遍了

 #include <cstdio>
#include <algorithm>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <iostream>
#include <cmath> using namespace std;
typedef long long LL;
typedef unsigned long long ull;
const int INF=;
const int maxn=+; ull l, r;
string up, down;
ull ans = ; int lup, ldown; int check(string &tmp)
{
if(tmp == "") return ;
int len = tmp.size(); if (len > lup && len < ldown) return ;
if (len == lup && len != ldown && tmp >= up) return ;
if (len == ldown && len != lup && tmp <= down) return ;
if (len == lup && len == ldown && tmp >= up && tmp <= down) return ;
return ;
} int main(){ cin >> l >> r; up = down = "";
while(l)
{
up = (char)(l % + '') + up;
//cout << up << endl;
l >>= ;
} while(r)
{
down = (char)(r % + '') + down;
r >>= ;
} lup = up.size(), ldown = down.size(); // string t;
// cin >> t;
// cout << check(t) << endl; for (int len = lup; len <= ldown; len++)
{
//cout << len << endl;
string tmp = "";
for (int i = ; i <= len; i++)
{
string one = "";
for (int tim = ; tim <= i; tim++)
one += ''; for (int j = ; j <= len; j++)
{
if(i + j > len) continue; string zero = "";
for (int tim = ; tim <= j; tim++)
zero += ''; if (len%(i+j) != && len%(i+j) != i) continue; tmp = "";
int maxtim = len/(i+j); for (int tim = ; tim <= maxtim; tim++)
tmp += one+zero; if (len % (i+j) != )
tmp += one; if (check(tmp))
{
ans++;
//cout << tmp << endl;
} //cout << tmp << endl;
}
} tmp = "";
for (int tim = ; tim <= len; tim++)
tmp += '';
if (check(tmp))
{
ans++;
//cout << tmp << endl;
}
} cout << ans << endl;
return ; }

最新文章

  1. LoadRunner 函数之lr_xml_find
  2. windows下命令行打jar包方法
  3. poj1631Bridging signals(最长单调递增子序列 nlgn)
  4. Requirements Gathering
  5. InnoDB的redo日志管理---饶珑辉
  6. 使用C#实现顺序队列
  7. 【redis 基础学习】(六)Redis HyperLogLog
  8. c/c++ 网络编程 UDP 用if_nameindex和ioctl取得主机网络信息
  9. .NET, ASP.NET, ADO.NET, C# 区别
  10. http://lib.csdn.net/article/reactnative/40118
  11. Redis整理
  12. centos6.4 安装wireless驱动
  13. 各个JAVA场景下的内存图
  14. create-react-app时registry的奇怪问题
  15. C++范围解析运算符::的使用
  16. javascript+dom编程艺术 读后感
  17. 九度OJ 1184:二叉树遍历 (二叉树)
  18. COdevs 天梯 水题系列
  19. codeforces 688B B. Lovely Palindromes(水题)
  20. 我的liunx开发环境的配置之路

热门文章

  1. stringstream 用法
  2. linux还原svn
  3. (三)js循环结构
  4. HDU - 6241 :Color a Tree(不错的二分)
  5. P2P技术基础: 关于TCP打洞技术
  6. JDBC 3 通过PreparedStatement 对数据库进行增删改查
  7. ORA-28595: Extproc 代理: DLL 路径无效解决办法
  8. Java开发过程中乱码问题理解
  9. 关于 SMT 一个重要提示
  10. (转)Oracle存储过程中的事务