Gym - 101128H:Sheldon Numbers
2024-08-23 13:50:33
题意
给你两个整数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 ; }
最新文章
- LoadRunner 函数之lr_xml_find
- windows下命令行打jar包方法
- poj1631Bridging signals(最长单调递增子序列 nlgn)
- Requirements Gathering
- InnoDB的redo日志管理---饶珑辉
- 使用C#实现顺序队列
- 【redis 基础学习】(六)Redis HyperLogLog
- c/c++ 网络编程 UDP 用if_nameindex和ioctl取得主机网络信息
- .NET, ASP.NET, ADO.NET, C# 区别
- http://lib.csdn.net/article/reactnative/40118
- Redis整理
- centos6.4 安装wireless驱动
- 各个JAVA场景下的内存图
- create-react-app时registry的奇怪问题
- C++范围解析运算符::的使用
- javascript+dom编程艺术 读后感
- 九度OJ 1184:二叉树遍历 (二叉树)
- COdevs 天梯 水题系列
- codeforces 688B B. Lovely Palindromes(水题)
- 我的liunx开发环境的配置之路