题意

给你两个整数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 ; }

Gym - 101128H:Sheldon Numbers的更多相关文章

  1. Sheldon Numbers GYM -- 枚举

    Sheldon Numbers GYM 题意:定义Sheldon Number为其二进制数是ABA……ABA型的或者ABAB……AB的,其中A全为1,B全为0(A>0, B>0),问[m, ...

  2. UVALive 7279 Sheldon Numbers (暴力打表)

    Sheldon Numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/127406#problem/H Description According t ...

  3. UVA - 13022 Sheldon Numbers(位运算)

    UVA - 13022 Sheldon Numbers 二进制形式满足ABA,ABAB数的个数(A为一定长度的1,B为一定长度的0). 其实就是寻找在二进制中满足所有的1串具有相同的长度,所有的0串也 ...

  4. POJ 3252:Round Numbers

    POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...

  5. Gym 101128F Sheldon Numbers(网络流)

    [题目链接] http://codeforces.com/gym/101128/attachments [题目大意] 给出一张地图,分为高地和低地,高低地的交界线上划有红线, 现在要开小车跨过每条红线 ...

  6. Codeforces Gym 101142C:CodeCoder vs TopForces(搜索)

    http://codeforces.com/gym/101142/attachments 题意:每个人在TC和CF上分别有两个排名,如果有一个人在任意一个网站上大于另一个人的排名,那么这个人可以打败另 ...

  7. Project Euler 88:Product-sum numbers 积和数

    Product-sum numbers A natural number, N, that can be written as the sum and product of a given set o ...

  8. Geeks Interview Question: Ugly Numbers

    Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence1, 2, 3, 4, 5, 6, 8, 9, ...

  9. POJ 1142:Smith Numbers(分解质因数)

                                   Smith Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submiss ...

随机推荐

  1. ngxtop实时监控nginx状态

    ngxtop实时解析nginx访问日志,并且将处理结果输出到终端,功能类似于系统命令top,所以这个软件起名ngxtop.有了ngxtop,你可以实时了解到当前nginx的访问状况,再也不需要tail ...

  2. 感觉有变良好的第一次电面——yahoo北京测试实习生

    一个月之前投的岗位.都已经忘了.昨天突然接到电话说今天下午3点电面. 立马又开始忐忑起来,整理了下项目啊,推荐系统相关知识啥的,跑到欧巴桑寝室去电面电面. 3点很准时的电话来了,是个女面试官. 一上来 ...

  3. nginx time_wait 较多优化

    1. 查看命令   netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'   结果 ESTABLISHED 22 F ...

  4. Spring aop 记录操作日志 Aspect 自定义注解

    时间过的真快,转眼就一年了,没想到随手写的笔记会被这么多人浏览,不想误人子弟,于是整理了一个优化版,在这里感谢智斌哥提供的建议和帮助,话不多说,进入正题 所需jar包 :spring4.3相关联以及a ...

  5. Servlet概念入门

    什么是Servlet Servlet 为创建基于 web 的应用程序提供了基于组件.独立于平台的方法,可以不受 CGI 程序的性能限制.Servlet 有权限访问所有的 Java API,包括访问企业 ...

  6. (转)Download interrupted: Connection to https://dl-ssl.google.com refused

    (转)Download interrupted: Connection to https://dl-ssl.google.com refused   这个可能是网络问题,国内连google服务器经常连 ...

  7. PMODB GT202 WIFI的使用

    pHTTPSession = (P_HTTP_SESSION)malloc(ALIGN(sizeof(HTTP_SESSION))) PMODA/PMODB都可做WIFI使用,现介绍PMODB WIF ...

  8. BROCADE交换机配置

    BROCADE交换机配置一 与交换机交互,可以使用三种方式: 串口 以太网口 光纤口 缺省的串口参数是:9600,N,8,1 缺省IP访问方式是: IP地址: 10.77.77.77 用户名: adm ...

  9. MySQL存储过程中的3种循环,存储过程的基本语法,ORACLE与MYSQL的存储过程/函数的使用区别,退出存储过程方法

    在MySQL存储过程的语句中有三个标准的循环方式:WHILE循环,LOOP循环以及REPEAT循环.还有一种非标准的循环方式:GOTO,不过这种循环方式最好别用,很容易引起程序的混乱,在这里就不错具体 ...

  10. oracle11.2 安装

    win10安装oracle 11g 时出现INS-13001环境不满足最低要求 oracle在win10上安装教程