UVa 11645 Bits (暴力+组合数学)
题意:给定一个数 n,求 0 ~ n,中二进制表示中连续两个 1 出现的次数。
析:枚举连续的两个 1,从低位向高位进行枚举,然后前可以是任意数,后面也是任意的,如果 n 正好是 11 还要另算,举个例子。
10110,假设现在枚举第 2 位和第 3 位,那么出现的次次数就是前面的 10,还有第一位是任意的,所以就有 10 = 2 * 2 = 4 种,而且正好第 2 位和第 3 位是 1,那么对于第一位也是是随便的,再加上 2。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#include <numeric>
#define debug() puts("++++")
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define be begin()
#define ed end()
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
//#define all 1,n,1
#define FOR(i,n,x) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.in", "r", stdin)
#define freopenw freopen("out.out", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e17;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1500 + 50;
const int maxm = 1e6 + 10;
const LL mod = 1000000000000000LL;
const int dr[] = {-1, 1, 0, 0, 1, 1, -1, -1};
const int dc[] = {0, 0, 1, -1, 1, -1, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
}
inline int readInt(){ int x; scanf("%d", &x); return x; } LL p, q;
void add(LL x){
q += x;
p += q / mod;
q %= mod;
} int main(){
int kase = 0;
LL n;
while(cin >> n && n >= 0){
p = q = 0;
LL m = 1LL, t = n;
while(n){
add((n>>2) * m);
if((n&3) == 3) add((t&m-1) + 1);
n >>= 1;
m <<= 1;
}
printf("Case %d: ", ++kase);
if(p) printf("%lld%015lld\n", p, q);
else printf("%lld\n", q);
}
return 0;
}
UVa 11645 Bits (暴力+组合数学)的更多相关文章
- UVA 11645 - Bits(数论+计数问题)
题目链接:11645 - Bits 题意:给定一个数字n.要求0-n的二进制形式下,连续11的个数. 思路:和 UVA 11038 这题相似,枚举中间,然后处理两边的情况. 只是本题最大的答案会超过l ...
- UVA 11645 Bits(组合数学)
从左往右处理,左半部分记为left, 右半部分记为right,若i,i -1均为1, 贡献为ans += (left + 1) + right * (1ll << (i - 1)); 否则 ...
- UVA.10325 The Lottery (组合数学 容斥原理 二进制枚举)
UVA.10325 The Lottery (组合数学 容斥原理) 题意分析 首先给出一个数n,然后给出m个数字(m<=15),在[1-n]之间,依次删除给出m个数字的倍数,求最后在[1-n]之 ...
- UVA.725 Division (暴力)
UVA.725 Division (暴力) 题意分析 找出abcdefghij分别是0-9(不得有重复),使得式子abcde/fghij = n. 如果分别枚举每个数字,就会有10^10,肯定爆炸,由 ...
- 10年省赛-Greatest Number (二分+暴力) + 12年省赛-Pick apples(DP) + UVA 12325(暴力-2次枚举)
题意:给你n个数,在里面取4个数,可以重复取数,使和不超过M,求能得到的最大的数是多少: 思路:比赛时,和之前的一个题目很像,一直以为是体积为4(最多选择四次)的完全背包,结果并不是,两两求和,然后二 ...
- Chinese Mahjong UVA - 11210 (暴力+回溯递归)
思路:得到输入得到mj[]的各个牌的数量,还差最后一张牌.直接暴力枚举34张牌就可以了. 当假设得到最后一张牌,则得到了的牌看看是不是可以胡,如果可以胡的话,就假设正确.否者假设下一张牌. 关键还是如 ...
- UVA 1262 Password 暴力枚举
Password Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA. Original ID: ...
- 紫书 例题 10-2 UVa 12169 (暴力枚举)
就是暴力枚举a, b然后和题目给的数据比较就ok了. 刘汝佳这道题的讲解有点迷,书上讲有x1和a可以算出x2, 但是很明显x2 = (a * x1 +b) 没有b怎么算x2?然后我就思考了很久,最后去 ...
- 紫书 习题 8-2 UVa 1610 (暴力出奇迹)
这道题我真的想的非常的复杂, 拿草稿纸一直在找规律,推公式, 然后总有一些特殊的情况. 然后就WA了N次.无奈之下看了别人的博客, 然后就惊了.直接暴力枚举两个相邻字符串 里面的所有可能就可以了--真 ...
随机推荐
- Struts2 xxAction-validation.xml使用
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE validators PUBLIC &quo ...
- tensorflow-yolo3系列配置文章汇总
yolo 网络讲解 https://blog.csdn.net/m0_37192554/article/details/81092514 https://blog.csdn.net/guleileo/ ...
- JDK1.7 ConcurrentHashMap--解决高并发下的HashMap使用问题
高并发下也可以使用HashTable .Collections.synchronizedMap因为他们是线程安全的,但是却牺牲了性能,无论是读操作.写操作都是给整个集合加锁,导致同一时间内其他操作均为 ...
- Linux命令:cd
语法 cd [-L|[-P [-e]]] [dir]改变shell当前工作目录.仅对执行命令所在的shell有效. 参数 -L 按符号链接进入目录. -P 按物理链接进入目录 -e 如果指 ...
- pycharm的断点调试【转自https://blog.csdn.net/weixin_39198406/article/details/78873120】
1. show execution point (F10)显示目前项目所有断点2. step over (F8)下一步但仅限于设置断点的文件3. step into (F7)执行下一行4. step ...
- R语言-线图(二)
1.线图示例 plot()为高水平作图命令,axis().lines().legend()都为低水平作图命令 > rain<-read.csv("cityrain.csv&q ...
- mysql_day02
MySQL-Day01回顾1.MySQL的特点 1.关系型数据库 2.跨平台 3.支持多种编程语言2.MySQL的启动和连接 1.服务端启动 sudo /etc/init.d/mysql start| ...
- python 迭代器生成
博客:http://www.cnblogs.com/alex3714/articles/5765046.html 列表生成式 [i*2 for i in range(10)] #创建时就生成,不调用也 ...
- 拿来主义:treeview插件父子节点问题
鄙人公司没有专门的前端,所以项目开发中都是前后端一起抡.最近用bootstrap用的比较频繁,发现bootstrap除了框架本身的样式组件外,还提供了多种插件供开发者选择.本篇博文讲的就是bootst ...
- Centos7下安装Docker[z]
[z]https://www.cnblogs.com/qgc1995/p/9553572.html https://yq.aliyun.com/articles/691610?spm=a2c4e.11 ...