D - Round Numbers

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, Paper, Stone' (also known as 'Rock, Paper, Scissors', 'Ro, Sham, Bo', and a host of other names) in order to make arbitrary decisions such as who gets to be milked first. They can't even flip a coin because it's so hard to toss using hooves.

They have thus resorted to "round number" matching. The first cow picks an integer less than two billion. The second cow does the same. If the numbers are both "round numbers", the first cow wins,
otherwise the second cow wins.

A positive integer N is said to be a "round number" if the binary representation of N has as many or more zeroes than it has ones. For example, the integer 9, when written in binary form, is 1001. 1001 has two zeroes and two ones; thus, 9 is a round number. The integer 26 is 11010 in binary; since it has two zeroes and three ones, it is not a round number.

Obviously, it takes cows a while to convert numbers to binary, so the winner takes a while to determine. Bessie wants to cheat and thinks she can do that if she knows how many "round numbers" are in a given range.

Help her by writing a program that tells how many round numbers appear in the inclusive range given by the input (1 ≤ Start < Finish ≤ 2,000,000,000).

Input

Line 1: Two space-separated integers, respectively Start and Finish.

Output

Line 1: A single integer that is the count of round numbers in the inclusive range Start.. Finish

Sample Input

2 12

Sample Output

6

解题:乱搞,找规律,毛线数位dp啊,搞死人

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
LL dp[] = {,,,,};
LL c[][];
void init() {
int i,j;
for(i = ; i <= ; i++) {
c[i][] = c[i][i] = ;
for(j = ; j < i; j++)
c[i][j] = c[i-][j-]+c[i-][j];
}
for(i = ; i <= ; i++){
for(j = ; j < i-j- ; j++)
dp[i] += c[i-][j];
dp[i] += dp[i-];
}
}
LL analysis(int x,int y,int base){
int i,j;
LL ans = ;
for(i = ; i+x <= base-i+y; i++)
ans += c[base][i];
return ans;
}
LL cal(int x) {
if(x == || x == ) return ;
int d[],i,len,one = ,zero = ;
LL ans = ;
for(len = ; x; x >>= ,len++) {
d[len] = x&;
}
ans += dp[len-];
one++;
for(i = len-; i > ; i--) {
if(d[i]) {
ans += analysis(one,zero+,i);
one++;
} else zero++;
}
if(d[]){
if(one == zero || one == zero+) ans += ;
else if(one < zero) ans += ;
one++;
}else zero++;
if(one >= && d[] == && one <= len - one) ans++;
return ans;
}
int main() {
init();
int a,b,i = ;;
while(~scanf("%d %d",&a,&b))
printf("%I64d\n",cal(b)-cal(a-));
return ;
}

xtu summer individual 1 D - Round Numbers的更多相关文章

  1. xtu summer individual 1 E - Palindromic Numbers

    E - Palindromic Numbers Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %l ...

  2. 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP

    [BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...

  3. POJ 3252 Round Numbers

     组合数学...(每做一题都是这么艰难) Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7607 A ...

  4. [BZOJ1662][POJ3252]Round Numbers

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

  5. Round Numbers(组合数学)

    Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10484 Accepted: 3831 Descri ...

  6. POJ 3252 Round Numbers(组合)

    题目链接:http://poj.org/problem?id=3252 题意: 一个数的二进制表示中0的个数大于等于1的个数则称作Round Numbers.求区间[L,R]内的 Round Numb ...

  7. poj3252 Round Numbers

    Round Numbers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7625   Accepted: 2625 Des ...

  8. bzoj1662: [Usaco2006 Nov]Round Numbers 圆环数

    Description 正如你所知,奶牛们没有手指以至于不能玩“石头剪刀布”来任意地决定例如谁先挤奶的顺序.她们甚至也不能通过仍硬币的方式. 所以她们通过"round number" ...

  9. Round Numbers (排列组合)

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7558   Accepted: 2596 Description The c ...

随机推荐

  1. hibernate Day2

    Day21 实体类编写规则(1 ) 实体类中的属性是私有属性(2) 私有属性要生成get与set方法(3) 实体类中有属性作为唯一值(一般使用id值)(4) 实体类属性建议不要使用基本数据类型, 应当 ...

  2. PHP fgets 函数

    <?php $handle=fopen("../good/html/1.txt","r"); ; //打开一个远程文件 $content="&q ...

  3. Coco dfs 或者 状压dp。...

    C -- Coco Time Limit:1s Memory Limit:64MByte Submissions:148Solved:85 DESCRIPTION Coco just learned ...

  4. 01_C++学习笔记_入门

    1.float类型只能表示数字里面的前6位或者前7位.也就是说c++只能保证float类型的数字的前6位是正确的.如果要求的精度更高的话,请使用double和long double. float精度是 ...

  5. SpringBoot 2.x (6):使用Filter、Servlet、Listener

    Filter的使用: 1.常见的默认Filter有: characterEncodingFilter hiddenHttpMethodFilter httpPutFormContentFilter r ...

  6. Firefox离线安装扩展教程

    Firefox离线安装扩展教程 解决问题博文:解决stackoverflow打开慢不能注册登录 应网友求助在上传了需要的扩展资源后,顺便写个离线安装方法,其实百度也行,这不写下来后为需求者省事.(*^ ...

  7. checking for gcc... no

    ./configure 后显示checking for gcc... nochecking for cc... nochecking for cl.exe... noconfigure.sh:erro ...

  8. Javaweb学习笔记7—JDBC技术

      今天来讲javaweb的第7阶段学习. JDBC技术,关于JDBC本篇博客只介绍了它的一部分,后面博客会更加深入探讨. 老规矩,首先先用一张思维导图来展现今天的博客内容.   ps:我的思维是用的 ...

  9. H3C S5024P交换机互连实验

    第一次周二网络管理实验报告 交换机互联实验 实验接线图: 交换机全貌: 可以通过超级终端和telnet来配置交换机       控制电缆连交换机console口与计算机主机(只可以传送命令不可以通信, ...

  10. systemtap执行过程中报probe timer.profile registration error

    probe timer.profile registration error 今天在执行火焰图的过程中,代码报错,probe timer.profile registration error 经过查询 ...