题目大意:给两个数字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 用post请求调用接口api

    $post_data=""; $ch = curl_init(); $url = ''; curl_setopt($ch , CURLOPT_URL , $url); curl_s ...

  2. xml配置与使用

    php100:89:xml常识知识补充 xml常识知识补充XML(即可扩展标记语言,它与HTML一样,都是标准通用标记语言.Xml是Internet环境中跨平台的,依赖于内容的技术.扩展标记语言XML ...

  3. sql错误代码一览表

    http://docstore.mik.ua/orelly/java-ent/jenut/ch08_06.htm Table 8-3. SQL-92 SQLSTATE Return Codes Cla ...

  4. Python交互模式下方向键出现乱码

    解决办法如下: 1.安装readline模块 readline库是bash shell用的库,包含许多功能,如命令行自动补全等. ubuntu下安装的命令:   sudo apt-get instal ...

  5. 转:iOS 7人机界面准则

    原文来自于:http://www.infoq.com/cn/news/2014/02/ios-ui-design Apple官方推出的“iOS人机界面准则”一直被iOS开发者奉为绝对的设计参考宝典,特 ...

  6. log4net 学习笔记

    记入最基本的用法 : refer : http://www.cnblogs.com/aehyok/archive/2013/05/07/3066010.html <configuration&g ...

  7. Altium designer PCB中过孔铺地连接的设置

    在Altium designer 6及更高版本如Altium Designer Winter 9.altium designer summer 9都会有这样的问题,在Altium DXP2004里面是 ...

  8. ListView的getFirstVisiblePosition等方法返回的是哪个对象

    int firstPosition = lisView.getFirstVisiblePosition(); int lastPosition = lisView.getLastVisiblePosi ...

  9. 【转】你应该知道的 10 个 VirtualBox 技巧与高级特性

    原文网址:http://www.oschina.net/translate/10-virtualbox-tricks-and-advanced-features-you-should-know-abo ...

  10. Android样式的编写格式

    <?xml version="1.0" encoding="utf-8"?> <resources> <style name=&q ...