Problem B:http://codeforces.com/contest/611/problem/B

B. New Year and Old Property

题意:问输入的年份a到b中转化为二进制后只有一个0的年份有几个。 

思路:不会位运算,当时没写出来,不过听说dfs就可以了

#include<bits/stdc++.h>  
#define LL long long  
using namespace std;  
LL a,b,t;  
void dfs(LL x,LL y){  
    if(x>b)  
    return;  
    if(a<=x&&x<=b&&y==1)  
    t++;  
    if(y==0)  
    dfs(x*2,y+1);  
      
    dfs(x*2+1,y);  
}  
int main(){  
    cin>>a>>b;  
    t=0;  
    dfs(1,0);  
    cout<<t<<endl;  
    return 0;  
} 

 

相关文章:

  • 2021-09-15
  • 2022-12-23
  • 2021-07-26
  • 2021-09-11
  • 2021-09-04
  • 2021-10-27
  • 2021-09-29
  • 2021-08-15
猜你喜欢
  • 2021-11-04
  • 2021-10-22
  • 2021-08-09
  • 2021-11-28
  • 2021-09-03
  • 2021-06-03
  • 2021-07-12
相关资源
相似解决方案