JZOJ 3084. 【NOIP2012模拟11.3】超级变变变

编程入门 行业动态 更新时间:2024-10-28 18:36:44

<a href=https://www.elefans.com/category/jswz/34/1752564.html style=JZOJ 3084. 【NOIP2012模拟11.3】超级变变变"/>

JZOJ 3084. 【NOIP2012模拟11.3】超级变变变

Are you ready?

  • 题目:
  • 分析:
  • 代码:


题目:

传送门


分析:

考场上推了一年,发现仍然不可做,然后就放弃了
结果居然有规律,我******出题人
我的做法是通过构建一颗按照 f f f函数的二叉树,然后逐层求解


代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<ctime>
#include<iomanip>
#include<string>
#include<bitset>
#include<deque>
#include<set>
#define LL long long
using namespace std;
inline LL read(){LL d=0,f=1;char s=getchar();while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}return d*f;
}
LL p[100];
LL k,n,m;
LL ask(LL x)
{if(k==1||!k) return x;LL sum=0;if(k%2==1){if(k<=x) sum++;for(LL i=1;k*p[i]<=x;i++) sum+=min(p[i],x-k*p[i]+1);return sum;}if(k<=x) sum++;if(k<x) sum++;for(LL i=1;k*p[i]<=x;i++) sum+=min(p[1+i],x-k*p[i]+1);return sum;
}
int main()
{k=read();n=read();m=read();p[0]=1;for(LL i=1;i<63;i++) p[i]=p[i-1]*2;cout<<ask(m)-ask(n-1);return 0;
}

更多推荐

JZOJ 3084. 【NOIP2012模拟11.3】超级变变变

本文发布于:2024-03-08 17:30:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1721625.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:JZOJ   变变变

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!