Gym - 101128H:Sheldon Numbers
题意
给你两个整数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的更多相关文章
- Sheldon Numbers GYM -- 枚举
Sheldon Numbers GYM 题意:定义Sheldon Number为其二进制数是ABA……ABA型的或者ABAB……AB的,其中A全为1,B全为0(A>0, B>0),问[m, ...
- UVALive 7279 Sheldon Numbers (暴力打表)
Sheldon Numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/127406#problem/H Description According t ...
- UVA - 13022 Sheldon Numbers(位运算)
UVA - 13022 Sheldon Numbers 二进制形式满足ABA,ABAB数的个数(A为一定长度的1,B为一定长度的0). 其实就是寻找在二进制中满足所有的1串具有相同的长度,所有的0串也 ...
- POJ 3252:Round Numbers
POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...
- Gym 101128F Sheldon Numbers(网络流)
[题目链接] http://codeforces.com/gym/101128/attachments [题目大意] 给出一张地图,分为高地和低地,高低地的交界线上划有红线, 现在要开小车跨过每条红线 ...
- Codeforces Gym 101142C:CodeCoder vs TopForces(搜索)
http://codeforces.com/gym/101142/attachments 题意:每个人在TC和CF上分别有两个排名,如果有一个人在任意一个网站上大于另一个人的排名,那么这个人可以打败另 ...
- 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 ...
- 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, ...
- POJ 1142:Smith Numbers(分解质因数)
Smith Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submiss ...
随机推荐
- linux下安装boost
linux平台下要编译安装除gcc和gcc-c++之外,还需要两个开发库:bzip2-devel 和python-devel,因此在安装前应该先保证这两个库已经安装:#yum install gcc ...
- MySql必知必会实战练习(六)游标
游标主要用于交互式应用,滚动屏幕上的数据,并对数据进行浏览或做出更改 看一下下面的例子: drop procedure IF EXISTS processorders; create procedur ...
- iOS6 自动布局 入门–Auto Layout
目前为止,即使你的界面设计是在合理的复杂度内,你也必须要为之写许多代码来适应变化的布局.现在我相信你会很高兴听到这种情况将不会发生了-对于iPhone与iPad IOS6 带来了一个非常了不起的特征: ...
- C# null和" "的区别
String str1 = null; str引用为空 String str2 = ""; str引用一个空串 也就是null没有分配空间,""分 ...
- setContentHuggingPriority和setContentCompressionResistancePriority的使用
当两个UILabel并排显示时,如何设置约束,让 leftLB 和 rightLB 正常显示就很重要了. 方案1:左右两个Label的宽度相同,则约束设置如下: //添加标题约束,左边的label [ ...
- zabbix 执行自定义key脚本超时
报错如下: [root@master scripts]# /usr/local/zabbix/bin/zabbix_get -s 127.0.0.1 -k web.site.code[www.baid ...
- LaunchImage添加以及设置无效处理
1.添加LaunchImage 2.添加所需要图片即可,出现un..可以删除,警告也随之而去,并删除LauchImage Assets之后重新添加 3.确定设置是否一样 4.发现启动后加载不了启动图, ...
- 如何删除xcode 中过期的描述性文件
1.使用终端 首先 打开终端 cd ~/Library/MobileDevice/Provisioning\ Profiles/再删除所有 rm *.mobileprovision 2.直接找到文件夹 ...
- Python--urllib3库
Urllib3是一个功能强大,条理清晰,用于HTTP客户端的Python库,许多Python的原生系统已经开始使用urllib3.Urllib3提供了很多python标准库里所没有的重要特性: 1 ...
- emqtt 3 (我要subscribe 这个topic)
这一次,主要分析client subscribe 某个topic 的处理流程. 由protocol开始 是的,还是要从protocol开始,至于为什么,之前就说过了. subscribe 类型的pac ...