POJ 3252 Round Numbers
Round NumbersTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 6553 Accepted: 2230DescriptionThe 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).InputLine 1: Two space-separated integers, respectively Start and Finish.OutputLine 1: A single integer that is the count of round numbers in the inclusive range Start..FinishSample Input2 12Sample Output6SourceUSACO 2006 November Silver这题让我说什么好呢,处理不好会有很多bug的,我查了一早上的代码,在吃饭回来的路上突然想到我早n种选0种的时候没有算,其实那是该算的,回来改了改给A了,哎,真是不想做这种题啊没有a的话,测一下数据吧。[cpp]#include <stdio.h>#include <string.h>#include <math.h>int base[50],top[50];int main(){long long int f(int m,int n);int i,j,l1,l2,sum,weishu,t;long long int n,m,s;scanf("%lld %lld",&n,&m);l1=l2=0;while(n!=0){base[l1++]=n%2;n=n/2;}while(m!=0){top[l2++]=m%2;m=m/2;}s=0;for(i=l1;i<=l2-1;i++){if(i%2==0){j=i/2;}else if(i%2!=0){j=i/2+1;}for(;j<=i-1;j++){ www.zzzyk.coms+=f(j,i-1);}}for(i=l2-2,sum=0;i>=1;i--){if(top[i]==1){if(l2%2==0){j=l2/2;}else{j=l2/2+1;}for(j=j-1-sum;j<=i; j++){if(j>=0){s+=f(j,i);}}}else{sum++;}}if(l2%2==0){weishu=l2/2;}else{weishu=l2/2+1;}if(top[0]==1){if(sum>=weishu){s+=2;}else{if((weishu-sum)==1){s++;}}}else{if((sum+1)>=weishu){s++;}}base[0]-=1; i=0;while(base[i]<0){base[i]+=2;base[i+1]-=1;i++;}t=l1;while(base[l1-1]==0){l1-=1;}if(l1==t){for(i=l1-2,sum=0;i>=1;i--){if(base[i]==1){if(l1%2==0){ &补充:软件开发 , C++ ,
上一个:九度1057 众数
下一个:idr机制(32叉树)
- 更多C/C++疑问解答:
- 关于c++的cout输出的问题。
- 在学校里学过C和C++,不过学的很一般,现在自学C#,会不会很难?
- 全国计算机二级C语言笔试题
- 已知某树有2个2度结点,3个3度结点,4个4度结点,问有几个叶子结点?
- c++数据结构内部排序问题,整数排序
- 2012九月计算机二级C语言全国题库,,急求急求
- 如果assert只有一个字符串作为参数,是什么意思呢?
- C语言中,哪些运算符具有左结合性,哪些具有右结合性,帮忙总结下,谢谢了!
- 为什么用结构体编写的程序输入是,0输不出来啊~~~
- 将IEEE—754的十六进制转化为十进制浮点类型,用C或C++都行,多谢各位大侠啊,非常感谢!
- 为什么这个程序求不出公式?
- 这个链表倒置的算法请大家分析下
- c语言函数库调用
- C语言unsigned int纠错
- C语言快排求解啊