2015년 12월 31일 목요일

B. New Year and Old Property

dfs, math

출처: Codeforces B. New Year and Old Property

SOL)

2진수로 표현하였을때
앞이 0이 아니며 0이 하나만 있는 수 구하기


cpp to html [-] Collapse
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<climits>
#include<cmath>
using namespace std;
typedef long long ll;

#define y1 mine
#define mp make_pair

double pi = acos(-1);

vector<ll> vec;

void dfs(ll v, ll c){
    if (c == 2) return;
    if (v > 1e18) return;
    if (c == 1) vec.push_back(v);
    dfs(v * 2 + 1, c);
    dfs(v * 2, c + 1);
}

int main(){
    //freopen("input.txt", "r", stdin);
    ll a, b;
    int ans = 0;

    scanf("%I64d %I64d", &a, &b);
    dfs(1, 0);
    sort(vec.begin(), vec.end());
    for (int i = 0; i < vec.size(); i++){
        if (a <= vec[i] &&  vec[i] <= b)
            ans++;
    }

    printf("%d", ans);

    return 0;
}

댓글 없음:

댓글 쓰기