POJ - 3252 A - Round Numbers
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
Output
Sample Input
2 12
Sample Output
6 题意:给出一个数据范围,求里面的圆数个数有多少,圆数的定义是化为无前导零二进制里面0的个数比1的个数多的话就是圆数
思路:首先我们范围比较大,我们一个一个判断不太现实,然后它其实就是求给定的二进制位里面0的个数多余1的个数就行,然后我们这个可以进行求一个组合数来解决 分为两部分进行求解
如 101010 我会先求出5位的时候,
那说明第一位是0 第二位是1
即 1????
再从四个位置里面算出0的个数比1的个数多的组合数
再判断4位 3位 2位 1位 第二部分即
100000-101010范围内
我们可以从高位开始判断 计算0 1 的数量
然后0直接忽略
当判断为1的时候,这时候我可以选择这个位置为0,后面的位置那我就可以随意怎么选求组合数
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
#include<stack>
#include<map>
using namespace std;
int C[][];
int a[];
int suan(int n)
{
int len=;
int k=n;
int sum=;
while(k)
{
a[++len]=k%;
k/=;
}
for(int i=;i<=len-;i++)
{
for(int j=i/+;j<=i;j++)
{
sum+=C[i][j];
}
}
int zero=;
for (int i=len-;i>=;i--)
{
if (a[i])
{
for (int j=(len+)/-(zero+);j<=i-;j++)
{
sum+=C[i - ][j];
}
}
else zero++;
}
return sum;
}
int main()
{
int n,m;
for(int i=;i<=;i++)
{
for(int j=;j<=i;j++)
{
if(i==j||!j) C[i][j]=;
else C[i][j]=C[i-][j-]+C[i-][j];
}
}
scanf("%d%d",&n,&m);
printf("%d\n",suan(m+)-suan(n));
}
POJ - 3252 A - Round Numbers的更多相关文章
- POJ 3252:Round Numbers
POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...
- POJ 3252 Round Numbers(组合)
题目链接:http://poj.org/problem?id=3252 题意: 一个数的二进制表示中0的个数大于等于1的个数则称作Round Numbers.求区间[L,R]内的 Round Numb ...
- POJ 3252 Round Numbers
组合数学...(每做一题都是这么艰难) Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7607 A ...
- [ACM] POJ 3252 Round Numbers (的范围内的二元0数大于或等于1数的数目,组合)
Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8590 Accepted: 3003 Des ...
- poj 3252 Round Numbers(数位dp 处理前导零)
Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, P ...
- POJ 3252 Round Numbers 数学题解
Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, P ...
- POJ 3252 Round Numbers 组合数学
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13381 Accepted: 5208 Description The ...
- POJ 3252 Round Numbers(组合数学)
Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10223 Accepted: 3726 De ...
- POJ 3252 Round Numbers(数位dp&记忆化搜索)
题目链接:[kuangbin带你飞]专题十五 数位DP E - Round Numbers 题意 给定区间.求转化为二进制后当中0比1多或相等的数字的个数. 思路 将数字转化为二进制进行数位dp,由于 ...
随机推荐
- Wannafly挑战赛26 B 冥土追魂
首先,证明结果一定是取某些整行,再加上一个多余的一行的前几个. 假如: x1<=x2<=x3<=x4<=x5 y1<=y2<=y3<=y4<=y5 取6 ...
- hdu-4080 Stammering Aliens 字符串hash 模板题
http://acm.hdu.edu.cn/showproblem.php?pid=4080 求出现次数大于等于n的最长串. #include<iostream> #include< ...
- Vue.js,select中的option用ajax想循环控制值的显示 v-model可以实现但提示报错,这是为什么?
应该将v-model换成:value,因为v-model只能绑定一个值,无法绑定多个值 <select v-model="citys"> <optio ...
- Sphinx实时索引
数据库中的数据很大,然后我有些新的数据后来加入到数据库中,也希望能够检索到,全部重新建立索引很消耗资源,这样需要用到“主索引+增量索引”的思路来解决,这个模式实现的基本原理是设置两个数据源和两个索引. ...
- Python操作excel的几种方式--xlrd、xlwt、openpyxl
openpyxl xlrd xlwt 在处理excel数据时发现了xlwt的局限性–不能写入超过65535行.256列的数据(因为它只支持Excel 2003及之前的版本,在这些版本的Excel中 ...
- Quartz理解与实现
记录关于Quartz定时调度任务的知识点,知识点主要分为两个部分,第一个部分介绍Quartz,第二部分使用Quartz+Spring来配置使用Quartz的实际操作. (一)Quartz知识点 Qua ...
- sqlserver给指定用户授权访问指定表
一. 背景 外部公司的人授权访问我们公司的数据库,数据接口调用,要给他们建立查看指定的视图和授权的账号,因此要在数据库中,给指定用户授权访问指定表 二.sqlserver 脚本 ---创建视图CR ...
- C++的成员初始化列表和构造函数体(以前未知)
成员的初始化列表和构造函数在对成员指定初值方面是不一样的.成员初始化列表是对成员初始化,而构造函数,是对成员赋值 成员初始化列表使用初始化的方式来为数据成员指定初值, 而构造函数的函数体是通过赋值的方 ...
- 7. 反转整数(Reverse Integer) C++
知识点: 内置变量 INT_MAX INT_MIN 运算结果是否溢出的判断 判断pop>7即pop>INT_MAX%10 判断pop<-8即pop<INT_MIN%10 c ...
- linux ssh root登陆出现错误:Permission denied, please try again
密码已检测过多遍还是登录失败 经检查 vim /etc/ssh/sshd_config PermitRootLogin no 改成 PermitRootLogin yes 修改之后重启就可以了