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 ...
随机推荐
- Hadoop TextInputFormat源码分析
from:http://blog.csdn.net/lzm1340458776/article/details/42707047 InputFormat主要用于描述输入数据的格式(我们只分析新API, ...
- sudo配置临时取得root权限
系统中的普通用户有时需要root权限执行某种操作,要是使用su - root的话必须要知道root的密码,这是不安全的,所以有了sudo,root可以对/etc/sudoers做一定的配置,让普通用户 ...
- C#外挂QQ找茬辅助源码,早期开发
这是一款几年前开发的工具,当年作为一民IT纯屌,为了当年自己心目中的一位女神熬夜开发完成.女神使用后找茬等级瞬间从眼明手快升级为三只眼...每次看到这个就会想起那段屌丝与女神的回忆.今天特地把代码更新 ...
- 利用 js 实现弹出蒙板(model)功能
关于 js 实现一个简单的蒙板功能(model) 思路: 创建一个蒙板, 设置蒙板的堆叠顺序保证能将其它元素盖住 position: absolute; top: 0; left: 0; displa ...
- Java8 Lambda sample (iwantmoon.com出品)
转载请注明出处:http://iwantmoon.com/Post/83a4497a74674612834965857e7bc044 .Net转到Java来,不知不觉已经有两年了,之前已经用习惯的li ...
- c++ 缺少动态库
http://www.cnblogs.com/smartvessel/archive/2011/01/21/1940868.html 总结下来主要有3种方法: . 用ln将需要的so文件链接到/usr ...
- 【BZOJ】【1037】【ZJOI2008】生日聚会party
DP orz iwtwiioi 这种题居然是DP……原来统计方案数是可以用动态规划来做的啊= =用一些变量来维护一些信息,保证方案可行性/合法性 人太弱实在是有些忧伤…… /************* ...
- 引入代码后,在@override报错
最近引入了spring的源码到工程里,发现凡是@override修饰的代码都会报错 这里有java历史的原因 5及以前不支持@override的注解,所以,此时,你最需要知道的是当前项目djk的编译版 ...
- 数据类型的处理(提取自FMDB)
if ((!obj) || ((NSNull *)obj == [NSNull null])) { sqlite3_bind_null(pStmt, idx); } // FIXME - someda ...
- 对LVS DR模式的理解
Client向vip发请求,lvs接收 Src mac Dst mac type … Src ip Src port Dst ip Dst port … CRC Mac1 Mac2 … … 192.1 ...