码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 5693 D Game 递归暴力

时间:2016-05-25 22:27:22      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:

http://blog.csdn.net/angon823/article/details/51484906

技术分享
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;
LL solve(LL x){
  if(x<=0)return 0;
   LL cur=1,ret=0;
   while(cur<x){
    cur=cur*2+1;
   }
   cur=(cur-1)/2;
   ret=(cur+1)/2;
   LL res=x-cur-1;
   return ret+1+res-(ret-solve(cur-res));
}
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
      LL l,r;
      scanf("%I64d%I64d",&l,&r);
      printf("%I64d\n",solve(r)-solve(l-1));
    }
    return 0;
}
View Code

 

HDU 5693 D Game 递归暴力

标签:

原文地址:http://www.cnblogs.com/shuguangzw/p/5528573.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!