栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 3252 Round Numbers

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 3252 Round Numbers

#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;long long s, e;long long f[50];long long com(long long n, long long r){    if (n <=0)        return 1;    if (n - r < r)        r = n - r;    long long i, j, s =1;    for (i =0, j =1; i < r; ++i)    {        s *= (n - i);        for (; j <= r && s % j ==0; ++j) s /= j;    }    return s;}long long cal(long long a){    long long num1, num0, bit =0, ret =0;    num1 = num0 =0;    long long x =1;    while (x <= a)    {        x <<=1;        bit++;    }    for (int i =1; i < bit; i++)        for (int j =0; j <= i /2-1; j++) ret += com(i -1, j);    long long pos = bit;    x >>=1;    num1++;    while (pos--, x >>=1)    {        if (x & a) num1++;        else        { num0++; continue;        }        for (long long i = pos -1; num1 -1+ (pos -1- i)<= num0 +1+ i && i >=0; i--) ret += com(pos -1, i);    }    return ret;}int main(){    scanf("%lld%lld", &s, &e);    printf("%lldn", cal(e +1) - cal(s));    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/376903.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号