poj 3252组合数学
2016-04-14 17:03
363 查看
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
题目有点长,大致的意思是在两头牛给出的范围内,数转化为二进制后,0比1多或者相等的数的个数
打表大法虽然好但是如果是2,000,000,000一定会超时,那么分析一下
int left,right; //左右区间
一个数转化成2进制区间就是2^n~2^n+1之间,那就有n位数,2,000,000,000转化成2进制为1,110,111,001,101,011,001,010,000,000,000有31位,那么就是right最大为31位的数,如果要0的数目大于等于1,那么就是
中j=0;j<=i/2;j++的所有排列组合
中间的数都解决了,那么靠近left和right的数怎么解决,那就是打表,如(10)d=(1010)b,那么比b大的就是11。。或者1011,也就是除了首位1遇到的第一个1以前可以放1的所有数加上本数除了首位1遇到的第一个1后面的数位含有的0的位数的c(j,i),同理也可以是小于。
最后贴代码
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
题目有点长,大致的意思是在两头牛给出的范围内,数转化为二进制后,0比1多或者相等的数的个数
打表大法虽然好但是如果是2,000,000,000一定会超时,那么分析一下
int left,right; //左右区间
一个数转化成2进制区间就是2^n~2^n+1之间,那就有n位数,2,000,000,000转化成2进制为1,110,111,001,101,011,001,010,000,000,000有31位,那么就是right最大为31位的数,如果要0的数目大于等于1,那么就是
中j=0;j<=i/2;j++的所有排列组合
中间的数都解决了,那么靠近left和right的数怎么解决,那就是打表,如(10)d=(1010)b,那么比b大的就是11。。或者1011,也就是除了首位1遇到的第一个1以前可以放1的所有数加上本数除了首位1遇到的第一个1后面的数位含有的0的位数的c(j,i),同理也可以是小于。
最后贴代码
相关文章推荐
- 简单的四则运算
- 数的奇偶性
- ACM网址
- 1272 小希的迷宫
- 1272 小希的迷宫
- hdu 1250 大数相加并用数组储存
- 矩阵的乘法操作
- 蚂蚁爬行问题
- 蚂蚁爬行问题
- 求两个数的最大公约数【ACM基础题】
- 打印出二进制中所有1的位置
- 杭电题目---一只小蜜蜂
- HDOJ 1002 A + B Problem II (Big Numbers Addition)
- 初学ACM - 半数集(Half Set)问题 NOJ 1010 / FOJ 1207
- 初学ACM - 组合数学基础题目PKU 1833
- POJ ACM 1002
- POJ 2635 The Embarrassed Cryptographe
- POJ 3292 Semi-prime H-numbers
- POJ 2773 HAPPY 2006
- ACM题库以及培养策略