题目大意:给两个数字a,b求出[a,b]中转化成二进制后0的个数大于等于1的个数的数

例如1100转化成10-11,100-111,1000-1011,1100。保证每个区段都有1打头,然后有一段数字任选用组合数求;

代码如下

#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int a[];
int c[][];
void table()
{
int i,j;
for(i=;i<=;i++)
{
for(j=;j<=i;j++)
{
if(!j||i==j)
c[i][j]=;
else
c[i][j]=c[i-][j-]+c[i-][j];
}
}
return;
}
int sum(int n){
if(n == )
return ;
int o = ; //转化成二进制的位数
while(n){
a[o++] = n%;
n/=;
}
int sum = ; //ans
int u = ; //二进制前面1的个数-0的个数
for(int i = o-; i >= ; i--){
if(a[i] == ){
if(i >= u){
for(int k = ; k <= i; k++){ //1的个数
if(k + u <= i - k){//printf("%d %d %d\n", i, k, c[i][k]);
sum += c[i][k];
}
}
}
u++;
}else u--;
}
//printf("%d %d \n", u, o);
u++;
if(u <= ){
sum ++;
}
for(int i = ; i < o-; i++){
for(int k = ; k <= i; k++){
if(+k <= i-k){
sum += c[i][k];
}
}
}
return sum;
}
int main(){
int a, b;
table();
while(scanf("%d%d", &a, &b)!=EOF){
printf("%d\n",sum(b) - sum(a-));
}
}

poj3252 组合数学的更多相关文章

  1. POJ3252——Round Number(组合数学)

    Round Numbers DescriptionThe cows, as you know, have no fingers or thumbs and thus are unable to pla ...

  2. [BZOJ1662][POJ3252]Round Numbers

    [POJ3252]Round Numbers 试题描述 The cows, as you know, have no fingers or thumbs and thus are unable to ...

  3. poj 3734 Blocks 快速幂+费马小定理+组合数学

    题目链接 题意:有一排砖,可以染红蓝绿黄四种不同的颜色,要求红和绿两种颜色砖的个数都是偶数,问一共有多少种方案,结果对10007取余. 题解:刚看这道题第一感觉是组合数学,正向推了一会还没等推出来队友 ...

  4. 组合数学or not ---- n选k有重

    模板问题: 1. 取物品 (comb.pas/c/cpp) [问题描述] 现在有n个物品(有可能相同),请您编程计算从中取k个有多少种不同的取法.[输入] 输入文件有两行,第一行包含两个整数n,k(2 ...

  5. 组合数学(全排列)+DFS CSU 1563 Lexicography

    题目传送门 /* 题意:求第K个全排列 组合数学:首先,使用next_permutation 函数会超时,思路应该转变, 摘抄网上的解法如下: 假设第一位是a,不论a是什么数,axxxxxxxx一共有 ...

  6. uestc1888 Birthday Party    组合数学,乘法原理

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=25539#problem/G 题目意思: 有n个人,每个人有一个礼物,每个人能拿 ...

  7. UVA 11076 Add Again 计算对答案的贡献+组合数学

    A pair of numbers has a unique LCM but a single number can be the LCM of more than one possiblepairs ...

  8. HDU4675【GCD of scequence】【组合数学、费马小定理、取模】

    看题解一开始还有地方不理解,果然是我的组合数学思维比较差 然后理解了之后自己敲了一个果断TLE.... 我以后果然还得多练啊 好巧妙的思路啊 知识1: 对于除法取模还需要用到费马小定理: a ^ (p ...

  9. hdu 4810 Wall Painting (组合数学+二进制)

    题目链接 下午比赛的时候没有想出来,其实就是int型的数分为30个位,然后按照位来排列枚举. 题意:求n个数里面,取i个数异或的所有组合的和,i取1~n 分析: 将n个数拆成30位2进制,由于每个二进 ...

随机推荐

  1. php resizeimage 部分jpg文件 生成缩略图失败

    今天遇到GD的resizeimage 函数处理jpg后缀文件的缩略图的时候 提示该图片不是合法的jpg图片并报错 <b>Warning</b>: imagecreatefrom ...

  2. DEDE常见问题(转)

    问题1. 把数据保存到数据库附加表 `dede_addonvisa` 时出错,请把相关信息提交给DedeCms官方.Unknown column 'redirecturl' in 'field lis ...

  3. PHP判断远程图片或文件是否存在

    PHP判断远程图片是否存在,此方法同样适用于判断远程文件是否存在,这是一种既然有效率且又准确的方法,建议采用此方法,以往使用get_headers()方法判断都是有问题的: function chec ...

  4. mysql命令行执行外部文件

    mysql命令行执行外部文件

  5. Collection Views and Building Custom Layouts-备

    UICollectionView的结构回顾 首先回顾一下Collection View的构成,我们能看到的有三个部分: Cells Supplementary Views 追加视图 (类似Header ...

  6. 2015年6月股灾永远载入A股史册

    之前很奇怪这次牛市行情的暴涨与暴跌,后来发现成交量是以往不可想象的,而这一切的源头就是融资融券,也就是杠杆. 杠杆的作用是无穷的,就像阿基米德说的那样“给我一个支点,我就能撬起地球”. 杠杆是个放大器 ...

  7. HDOJ 1196 Lowest Bit(二进制相关的简单题)

    Problem Description Given an positive integer A (1 <= A <= 100), output the lowest bit of A. F ...

  8. [转]The culture name list in C#

    Culture Names [C#] This example shows how to get all culture names in the .NET Framework. Use static ...

  9. HDU_2052——画矩形

    Problem Description Give you the width and height of the rectangle,darw it.   Input Input contains a ...

  10. openstack 手动 部署安装调试

    Virtual Interface creation failed