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 ...
随机推荐
- C#泛型类的类型约束
是使用泛型时,T默认情况下是不可以被初始化的,只能通过传值来赋值,这个时候可以使用类型约束来保证T是可以被约束的. .NET支持的类型参数约束有以下五种: where T: struct //T必须是 ...
- grep 常用正则匹配
1.或操作 grep -E '123|abc' filename // 找出文件(filename)中包含123或者包含abc的行 egrep '123|abc' filename // 用egrep ...
- DataBase project physical design
DataBase physical design //Table: /*student*/ create table student( id int not null primary key, /*学 ...
- vue动态 设置类名
<div class="tab"> <navigator :class="currentTab=='mzfw'?'nav active': 'nav'& ...
- docx转doc时,防止公式被转成图片的解决办法
编辑社回复需要doc(Word 97-2003)格式的文档,可是将docx(Word 2007+)另存为doc格式时,发现公式被转成了图片.其实,最简单的办法就是,打个电话过去给编辑社:“大爷,拜托您 ...
- HihoCoder1041 国庆出游 树形DP第四题
小Hi和小Ho准备国庆期间去A国旅游.A国的城际交通比较有特色:它共有n座城市(编号1-n):城市之间恰好有n-1条公路相连,形成一个树形公路网.小Hi计划从A国首都(1号城市)出发,自驾遍历所有城市 ...
- Linux 系统 LVM(Logical Volume Manager)逻辑卷管理
一.前言 每个Linux使用者在安装Linux时都会遇到这样的困境:在为系统分区时,如何精确评估和分配各个硬盘分区的容量,因为系统管理员不但要考虑到 当前某个分区需要的容量,还要预见该分区以后可能需要 ...
- 在idea下两个项目之间的maven父子级项目依赖
配置:idea 在一个项目中的父子级依赖网上轮子太多,我就不重复造了,留个链接 http://www.cnblogs.com/tibit/p/6185704.html 说说一些我自己注意的问题,在pr ...
- ssh面试题2
1. BeanFactory的作用是什么? [中] BeanFactory是配置.创建.管理bean的容器,有时候也称为bean上下文.Bean与bean的依赖关系,也是由BeanFactory负责维 ...
- 不让activity显示UI的办法
直接把 //setContentView(R.layout.activity_welcome); 注释掉就是了