E - BD String

众所周知,度度熊喜欢的字符只有两个:B和D。

今天,它发明了一种用B和D组成字符串的规则:

S(1)=B

S(2)=BBD

S(3)=BBDBBDD

S(n)=S(n−1)+B+reverse(flip(S(n−1))

其中,reverse(s)指将字符串翻转,比如reverse(BBD)=DBB,flip(s)指将字符串中的B替换为D,D替换为B,比如flip(BBD)=DDB。

虽然度度熊平常只用它的电脑玩连连看,这丝毫不妨碍这台机器无与伦比的运算速度,目前它已经算出了S(21000)的内容,但度度熊毕竟只是只熊,一次读不完这么长的字符串。它现在想知道,这个字符串的第L位(从1开始)到第R位,含有的B的个数是多少?

Input

第一行一个整数T,表示T(1≤T≤1000) 组数据。

每组数据包含两个数L和R(1≤L≤R≤1018) 。

Output

对于每组数据,输出S(21000)表示的字符串的第L位到第R位中B的个数。

Sample Input

3
1 3
1 7
4 8

Sample Output

2
4
3

把求l到r的变成,1到r减1到l,只要知道1到x又多少就可以了,如果恰好是2^k-1,那么就是2^(k-1),如果不是,就分成两部分左边是2^(k-1)-1,右边是2^(k-1)到x,在根据是对称取反加一的变化求

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h> 
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define sca(x) scanf("%d",&x)
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+100;
const double eps=1e-8;
using namespace std;
const double pi=acos(-1.0);
const int inf=0xfffffff;
const int N=1005;
ll num[65];
ll calc(ll x)
{
    if(x==0) return 0;
    if(x==1) return 1;
    if(x==2||x==3) return 2;
    ll i=0;
    while(i<x) i=i*2+1;
    i=(i-1)/2;
    return x-i+calc(i*2+1-x);
}
void first()
{
    int x=1;
    rep(i,1,61)
    {
        x*=2;
        num[i]=x-1;
    }
}
int main()
{
    ll re,l,r;
    first();
    cin>>re;
    while(re--)
    {
        cin>>l>>r;
        cout<<calc(r)-calc(l-1)<<endl;
    }
    return 0;
}

转载于:https://www.cnblogs.com/wzl19981116/p/9477806.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
public int convert2Ofd(int imagefileid, String filename,String docdcsurl) { writeLog("ConvertToPdfForDcsE9--convertUot2Ofd-------------------start"); //String docdcsurl = Util.null2String(getPropValue("yzDcsUrl", "docdcsurl")); writeLog("ConvertToPdfForDcsE9--convertUot2Ofd-------------------imagefileid=" + imagefileid + ";filename=" + filename + ";docdcsurl=" + docdcsurl); int newimagefileid = -1; try { if (imagefileid > 0 && !"".equals(filename) && !"".equals(docdcsurl)) { String fileext = ""; if (filename.indexOf(".") != -1) { fileext = filename.substring(filename.lastIndexOf(".")); } writeLog("ConvertToPdfForDcsE9--convertUot2Ofd-------------------fileext=" + fileext); String sourcefilepath = getImageFile(imagefileid + ""); writeLog("ConvertToPdfForDcsE9--convertUot2Ofd-------------------sourcefilepath=" + sourcefilepath); if (!"".equals(sourcefilepath)) { String dcsurl = convert(docdcsurl, sourcefilepath, "29"); writeLog("ConvertToPdfForDcsE9--convertUot2Ofd-------------------dcsurl=" + dcsurl); if (!"".equals(dcsurl)) { InputStream input = getInputStreamFromDcs(dcsurl); writeLog("ConvertToPdfForDcsE9--convertUot2Ofd-------------------input=" + input); String newfilename = filename.substring(0, filename.lastIndexOf(".")) + ".ofd"; if (input != null) { newimagefileid = savePdfImageFile(input, newfilename); } if (new File(sourcefilepath).exists() && new File(sourcefilepath).isFile()) { new File(sourcefilepath).delete(); } } } } } catch (Exception e) { writeLog("ConvertToPdfForDcsE9--convertUot2Ofd-------------------Exception=" + e); } writeLog("ConvertToPdfForDcsE9--convertUot2Ofd-------------------newimagefileid=" + newimagefileid); writeLog("ConvertToPdfForDcsE9--convertUot2Ofd-------------------end"); return newimagefileid; } 这段代码里2023-06-07 10:00:41,501 INFO A2 - [null] pool-20-thread-1-827[weaver.odoc.ofd.util.ConvertToPdfForDcs:395] - ConvertToPdfForDcsE9--convertUot2Ofd-------------------Exception=java.net.MalformedURLException: no protocol: {"data":{"fileHash":"f68995999879716524d33048cf89713eb6909b540af36f0c1326666747933f7f1","code":0,"destFileName":"5cf6fc7a-b466-4d2f-bd8a-90021ece7f03.ofd","srcFileName":"5cf6fc7a-b466-4d2f-bd8a-90021ece7f03.docx","srcFileSize":"1470724","destFileSize":"272921","convertType":29,"srcStoragePath":"f68995999879716524d33048cf89713eb/5cf6fc7a-b466-4d2f-bd8a-90021ece7f03.docx","destStoragePath":"2023/06/07/d897526c6b1848d38158e2d397dc1564/5cf6fc7a-b466-4d2f-bd8a-90021ece7f03.ofd","convertTime":"4224","viewUrl":"http://10.2.120.2:19090/fcscloud/view/preview/__u_3ZnLmSOahAqKi6icTcKJrPrgXJLd2m6bLJJ9Vy1AE7bOu07HXJe5EdV3ICfU4--G5-1b-C_BMkuxJ6YiThUP9cZrRTnS8WH7LNaAySY1b4J6VNRm5bUix26SO24700BVblzn6_Sgh3k8GCEv2iW5ceUlHmsE-UIfGUPobbnm9fShs4Gg-L5wSnmdcobmWgVCHNZvPMzNAj5FNM1RAAY0iGeLBNp1ezhgLFc-LsEC5fArMOLpbVonVHX-liJuUKBubUznMLCwaouob5HRqFnSwB6l-qEWFMyKeKK7yOknI8K-59iCZpKpUAzxt4hPezq1Pgh1nR1tTtwEypycLkvEnWyugeKTxu9mwyN_fFfIUyv6oV7P79BMIZt2o-B6kDJgXVaMxne2wjydgWr2nir306Hg_R0R0zS-Z4yG74g=/"},"message":"操作成功","errorcode":0}这个异常应该怎么修改
最新发布
06-08

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值