Sheldon Numbers GYM -- 枚举】的更多相关文章

Sheldon Numbers GYM 题意:定义Sheldon Number为其二进制数是ABA……ABA型的或者ABAB……AB的,其中A全为1,B全为0(A>0, B>0),问[m, n]中有多少个Sheldon Number. 思路:只需要存储好所有A与B的情况,并枚举所有的ABA……ABA型的或者ABAB……AB的情况. # include <bits/stdc++.h> using namespace std; # define vi vector < int &…
Sheldon Numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/127406#problem/H Description According to Sheldon Cooper, the best number is 73. In his own words, "The best number is 73. 73 is the 21st prime number. Its mirror, 37, is the 12th, and its m…
UVA - 13022 Sheldon Numbers 二进制形式满足ABA,ABAB数的个数(A为一定长度的1,B为一定长度的0). 其实就是寻找在二进制中满足所有的1串具有相同的长度,所有的0串也具有相同的长度,并且在给定范围内的个数. 位运算.通过分析不难发现,所有解不会很大,因此我们可以暴力,用两个for分别枚举0串和1串的长度,然后交替放入一个值内(注意先放1),同时更新答案. 将值存入set,发现所有满足条件的个数为4809(4810). ps:因为这里的2^63大于long lon…
https://vjudge.net/contest/174235#problem/H [题意] 求[x,y]之间有多少个Sheldon Number Sheldon Number是二进制满足以下条件的数: 可以写成ABABAB . . . ABA或ABABAB . . . AB,其中,A是连续的n个1,B是连续的m个0 这个二进制数可以没有0但不能没有1 [思路] 对于确定的n,m,和二进制数的长度len,二进制数唯一确定的,所以按n,m,len枚举的话复杂度为64^3 我们可以预处理所有的S…
[题目链接] http://codeforces.com/gym/101128/attachments [题目大意] 给出一张地图,分为高地和低地,高低地的交界线上划有红线, 现在要开小车跨过每条红线,当改变小车开的地形的时候,比如从高地开往低地, 就需要多耗油A单位,也可以花B的耗油量抬高地形或者降低地形, 问跨越所有红线所用的最少耗油量 [题解] 我们发现对于每条红线,我们需要花A去跨越地形或者花B去抬高或者降低地形, 所以我们将不同地形划分为两个集合,构成二分图, 红线左右块连流量为A的边…
题意 给你两个整数X和Y 问你在区间[X,Y]中,有多少数字的二进制满足ABAB或者A这种形式.A是某个数量的1,B是某个数量的0. 分析 因为数据规模很大,直接枚举x和y之间的数字然后判断会超时.所以直接构造符合的二进制串然后判断是不是在区间[X,Y]内就好.因为二进制串的长度最多只有63,所以随便枚举就行.但是写起来确实麻烦,容易出错的地方太多. 下面的代码是在场上两个队友写的,场上的代码嘛~可能有点乱~(好吧是我懒得再写一遍了 #include <cstdio> #include <…
A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, ... shows the first 20 humble numbers. Write a program to find and print the nth element i…
传送门:http://codeforces.com/contest/1081/problem/E E. Missing Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Chouti is working on a strange math problem. There was a sequence of nn …
2031. Overturned Numbers Time limit: 1.0 second Memory limit: 64 MB Little Pierre was surfing the Internet and came across an interesting puzzle: What is the number under the car? It took some time before Pierre solved the puzzle, but eventually he u…
题意:让求从2992-9999中所有数字,满足10进制各位之和和12进制和16进制各位数字之和相等. 析:没啥可说的,只能枚举从2992-9999,每个进制都算一下. 代码如下: #include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include <vector> #include <cstring> #include <map…