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】超级变变变
发布评论