POJ3252——Round Number(组合数学)
Round Numbers
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
题目大意:
问区间[a,b]中,有多少个数化成二进制后,0比1多。
解题思路:
组合数学问题。
看大牛博客过的。直接贴网址吧。
Code:
/*************************************************************************
> File Name: poj3252.cpp
> Author: Enumz
> Mail: 369372123@qq.com
> Created Time: 2014年10月29日 星期三 00时53分32秒
************************************************************************/ #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<list>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<climits>
#define MAXN 100000
using namespace std;
int com[][];
int num[];
void init()
{
for (int i=; i<=; i++)
for (int j=; j<=i; j++)
if (!j||i==j)
com[i][j]=;
else
com[i][j]=com[i-][j-]+com[i-][j];
}
int ret(int a)
{
memset(num,,sizeof(num));
num[]=;
while (a)
{
num[++num[]]=a%;
a/=;
}
int ans=;
for (int i=; i<=num[]-; i++)
for (int j=i/+;j<=i;j++)
ans+=com[i][j];
int zero=;
for (int i=num[]-;i>=;i--)
{
if (num[i])
for (int j=(num[]+)/-zero-;j<=i-;j++)
ans+=com[i-][j];
else zero++;
}
return ans;
}
int a,b;
int main()
{
init();
cin>>a>>b;
cout<<ret(b+)-ret(a)<<endl;
return ;
}
POJ3252——Round Number(组合数学)的更多相关文章
- [BZOJ1662][POJ3252]Round Numbers
[POJ3252]Round Numbers 试题描述 The cows, as you know, have no fingers or thumbs and thus are unable to ...
- [poj3252]Round Numbers_数位dp
Round Numbers poj3252 题目大意:求一段区间内Round Numbers的个数. 注释:如果一个数的二进制表示中0的个数不少于1的个数,我们就说这个数是Round Number.给 ...
- POJ 3252 Round Numbers 组合数学
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13381 Accepted: 5208 Description The ...
- poj3252-Round Number 组合数学
题目: Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8492 Accepted: 2963 ...
- Round Numbers(组合数学)
Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10484 Accepted: 3831 Descri ...
- poj3252 Round Numbers
Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7625 Accepted: 2625 Des ...
- POJ 3252 Round Number(数位DP)
Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6983 Accepted: 2384 Des ...
- POJ3252 Round Numbers —— 数位DP
题目链接:http://poj.org/problem?id=3252 Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Su ...
- poj3252 Round Numbers(数位dp)
题目传送门 Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 16439 Accepted: 6 ...
随机推荐
- 团队项目--“我爱淘”校园二手书店 NABC分析
本项目的特点之一:可查询功能 NABC分析: N(Need):方便校园里的学生查找自己需要的二手书籍,免了同学想买二手书还得跑到阿姨那里去看. A(Approach):将学生的信息和书籍的信息都存放在 ...
- kibana 修改Ico图标
修改此路径下的E:\happy\kinbana\kibana-4.2.2-windows\kibana-4.2.2-windows\optimize\bundles的commons.bundle.js ...
- ORM 框架
1.Dapper 2.Entity Framework(EF) http://www.cnblogs.com/n-pei/archive/2011/09/06/2168433.html
- Entity Framework走马观花之把握全局
在深入学习某项技术之前,应该努力形成对此技术的总体印象,并了解其基本原理,本文的目的就在于此. 一.理解EF数据模型 EF本质上是一个ORM框架,它需要把对象映射到底层数据库中的表,为此,它使用了三个 ...
- 用PHP对数据库数据进行删除
显示页面: <body> <table width="100%" border="1" cellpadding="0" c ...
- it小小鸟心得
本来打算就这么浑浑噩噩的过完我的大学四年生涯,但当我读完这本书,改变了我的想法.许多人说大学是最美好的,确实,在这里,我每天都不用认真听讲,不用准时去上课,可是久而久之,自己有感而发觉得这样碌碌无为下 ...
- JavaScript对象进阶
要了解JavaScript对象,我们可以从对象创建.属性操作.对象方法这几个方面入手.概括起来,包括以下几模块: 1.创建对象 1.1 对象直接量 对象直接量是创建对象最简单的方式,由若干名/值对组成 ...
- URAL
URAL 2035 输入x,y,c, 找到任意一对a,b 使得a+b==c&& 0<=a<=x && 0<=b<=y 注意后两个条件,顺序搞错 ...
- 0910 noip模拟
教师节快乐: T1:勇士闯魔塔,是一道很裸的莫队题目,但在老师的催促下,出题人@syq同学修改了第一题,使之成了一道送分题,全暴力水过: T2:第二题是一道预处理+分组背包,考试中,忘了分组背包怎么敲 ...
- [工作积累] bitfield
ISO/IEC 14882:2003: 9.6 Bit-fields [class.bit] A member-declarator of the form identifieropt : const ...