4725: [POI2017]Reprezentacje ró?nicowe
来源:互联网 发布:数据挖掘 常用模型 编辑:程序博客网 时间:2024/05/18 22:42
4725: [POI2017]Reprezentacje ró?nicowe
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 99 Solved: 48
[Submit][Status][Discuss]
Description
给定一个数列a:
当n<=2时,a[n]=n
当n>2,且n是奇数时,a[n]=2a[n-1]
当n>2,且n是偶数时,a[n]=a[n-1]+r[n-1]
其中r[n-1]=mex(|a[i]-a[j]|)(1<=i<=j<=n-1),mex{S}表示最小的不在S集合里面的非负整数。
数列a的前若干项依次为:1,2,4,8,16,21,42,51,102,112,224,235,470,486,972,990,1980。
可以证明,对于任意正整数x,只存在唯一一对整数(p,q)满足x=a[p]-a[q],定义为repr(x)。
比如repr(17)=(6,3),repr(18)=(16,15)。
现有n个询问,每次给定一个正整数x,请求出repr(x)。
Input
第一行包含一个正整数n(1<=n<=10^5)。
接下来n行,每行一个正整数x(1<=x<=10^9),表示一个询问。
Output
输出n行,每行两个正整数p,q,依次回答每个询问。
Sample Input
2
17
18
Sample Output
6 3
16 15
HINT
Source
鸣谢Claris上传
注意到奇数位置的生成公式
于是每隔两个位置就会扩大两倍
那么当算出大概前log2109 个f 时,最后面的那个数减前面的数的差值就很大了
显然这些对我们的查询没有贡献
因此只需要暴力算出前面一些位置的f
后面全部可以随便搞搞求出来
#include<iostream>#include<cstring>#include<cstdio>#include<map>#include<algorithm>using namespace std;const int N = 233;const int maxn = 1E5 + 10;const int Max = 1000000000;typedef long long LL;int tp,stk[maxn];LL f[N];map <int,pair<int,int> > M;inline int getint(){ char ch = getchar(); int ret = 0; while (ch < '0' || '9' < ch) ch = getchar(); while ('0' <= ch && ch <= '9') ret = ret * 10 + ch - '0',ch = getchar(); return ret;}int main(){ #ifdef DMC freopen("DMC.txt","r",stdin); #endif f[1] = 1; f[2] = 2; stk[tp = 1] = 1; M[1] = make_pair(2,1); for (int i = 3; i <= 70; i++) { if (!(i & 1)) { LL now; for (int k = 1; ; k++) if (!M.count(k)) {now = k; break;} f[i] = f[i - 1] + now; } else f[i] = f[i - 1] + f[i - 1]; for (int j = 1; j < i; j++) if (f[i] - f[j] <= Max) { stk[++tp] = f[i] - f[j]; M[f[i] - f[j]] = make_pair(i,j); } } sort(stk + 1,stk + tp + 1); int n = getint(); while (n--) { int x = getint(); pair <int,int> now; int pos = lower_bound(stk + 1,stk + tp + 1,x) - stk; if (stk[pos] == x) now = M[stk[pos]]; else { now.first = 70 + (x - pos + 1) * 2; now.second = now.first - 1; } printf("%d %d\n",now.first,now.second); } return 0;}
- 4725: [POI2017]Reprezentacje ró?nicowe
- bzoj 4725: [POI2017]Reprezentacje ró?nicowe 暴力
- BZOJ4725: [POI2017]Reprezentacje ró?nicowe
- BZOJ4725: [POI2017]Reprezentacje ró?nicowe
- BZOJ4726: [POI2017]Sabota?
- bzoj4723 [POI2017]Flappy Bird
- bzoj4726 [POI2017]Sabota?
- BZOJ4726 [POI2017]Sabota?
- 【BZOJ】4726 [POI2017] Sabota?
- BZOJ 4726 [POI2017] Sabota?
- BZOJ4723 [POI2017]Flappy Bird
- BZOJ4724 [POI2017]Podzielno
- 4726: [POI2017]Sabota?
- 4723: [POI2017]Flappy Bird
- BZOJ4727: [POI2017]Turysta
- [POI2017] Flappy Bird 题解
- 4724: [POI2017]Podzielno
- 4727: [POI2017]Turysta
- Java中的IO流
- 第七章
- android集成微信支付
- 基本乐理知识
- linux下使用UDP实现简易的多人聊天室
- 4725: [POI2017]Reprezentacje ró?nicowe
- FIddler : CustomRules.js脚本解析get请求被加密的参数
- Spring Aop 日志管理
- ACM-二分贪心U-21
- 数据结构之一元多项式相乘
- CentOS 6.5 Git服务器搭建
- LibGDX
- 苍木之凭
- scala broadcast