online_judge_1113
来源:互联网 发布:asp购物系统源码 编辑:程序博客网 时间:2024/06/05 18:39
#include <iostream>#include <cmath>using namespace std;int main(){ int m,n; int ans,t,i,r; while(cin>>m>>n) { if(n==0 && m==0) break; ans = 0; t = m; r = m; i=0; while(t <= n) { i++; t *= 2; r = 2*r + 1; } t /= 2; r /= 2; ans = pow(2, i-1) - 1; if(r < n) n = r; for(i=t; i<=n; ++i) ans++; cout<<ans<<endl; } return 0;}
北大的题目就是有意思,不特意考察编程能力。反倒是数学推理能力。也许这是最重要的吧!
下面的代码很漂亮,可以超时……
//此方法超时
#include <iostream>using namespace std;void countTree(int m, int n,int &ans){ if(m<=n) { ans++; countTree(2*m, n, ans); countTree(2*m+1, n, ans); }}int main(){ int m,n; int ans; while(cin>>m>>n) { if(n==0 && m==0) break; ans = 0; countTree(m, n, ans); cout<<ans<<endl; } return 0;}
0 0
- online_judge_1113
- 如何禁用开机启动项
- 登录时_ORACLE not available__解决方案
- java内存管理
- 广陵电商产业目前已呈现百花齐放的喜人格局
- Translation
- online_judge_1113
- 重载运算符 http://www.nowcoder.com/profile/380772/test/2198787/2593?onlyWrong=0
- Scala中的本地函数与作为语言一等公民的函数详解
- VMware Virtual Volume(VVOL)简介
- web统一资源定位符
- [javase学习笔记]-6.6 基本数据类型参数与引用数据类型参数的传递过程
- 云计算应用网络平台按内蒙古区域和行业划分来创建和管理
- 一张图说明CDN网络的原理
- php 安装gd模块