Description

一个数列.

\(a_1=1,a_2=2\)

当 \(n>2\) 时

\[a_n = \{  \begin {matrix} 2a_{n-1},\text{n is an odd number} \\ a_{n-1}+r_{n-1},\text{ n is an even number } \end{matrix} \]

\(S_n=\{a_i-a_j,1 \leqslant j<i\leqslant n\}\)

\(r_n\) 为最小不在 \(S_n\) 中的非负整数.

给出 \(x\),求一对 \((p,q)\) 使得 \(a_p-a_q=x\)

Sol

打表+二分.

可以发现 \(\{a_n\}\) 是一个单调递增的数列,而且有 \(*2\) 的递推式存在,所以当 \(n>2log_2 10^9\) 的时候小于 \(10^9\) 的差只可能是相邻的两个数字.

对于前面几行的元素直接打表存起来,后面的就二分一下在表内的元素算一下就可以了.

Code

/**************************************************************
Problem: 4725
User: BeiYu
Language: C++
Result: Accepted
Time:568 ms
Memory:5280 kb
****************************************************************/ #include <cstdio>
#include <utility>
#include <map>
#include <iostream>
using namespace std; #define mpr make_pair
typedef long long LL;
typedef pair< LL,LL > pr;
const int N = 505; LL p=1,n=65,m,T;
map< LL,pr > mp;
LL a[N][N];
LL b[N*N]; inline LL in(LL x=0,char ch=getchar()){ while(ch>'9' || ch<'0') ch=getchar();
while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();return x; } void _add(LL x,pr y){ mp[x]=y; }
LL _get(){ while(mp.count(p)) p++;return p; } int main(){
a[2][1]=1,mp[1]=mpr(2,1);
for(int i=3;i<=n;i++){
if(i&1){
for(int j=1;j<i;j++) a[i][i-1]+=a[j][j-1];
a[i][i-1]+=1;
}else{
a[i][i-1]=_get();
}
_add(a[i][i-1],pr(i,i-1));
for(int j=1;j<i-1;j++){
a[i][j]=a[i-1][j]+a[i][i-1];
_add(a[i][j],pr(i,j));
}
} for(map< LL,pr >::iterator it=mp.begin();it!=mp.end();it++) b[++m]=(*it).first; for(T=in();T--;){
LL l=1,r=m,mid,x;
x=in();
if(mp.count(x)){ printf("%lld %lld\n",mp[x].first,mp[x].second);continue; }
while(l<=r){
mid=(l+r)>>1;
if(b[mid]<x) l=mid+1;
else r=mid-1;
}
printf("%lld %lld\n",n+(x-r)*2-1,n+(x-r)*2-2);
}return 0;
}

  

BZOJ 4725: [POI2017]Reprezentacje ró?nicowe的更多相关文章

  1. bzoj 4725 [POI2017]Reprezentacje ró?nicowe 暴力

    [POI2017]Reprezentacje ró?nicowe Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 141  Solved: 67[Sub ...

  2. BZOJ4725: [POI2017]Reprezentacje ró?nicowe

    $n \leq 1e5$,$x \leq 1e9$. 1e9呵呵,暴力处理$a_n$的前几项直到1e9.然后处理出差的数列,每次在这里面找,找得到就回答,找不到,那有贡献的只有$a_i-a_{i-1} ...

  3. BZOJ 4727: [POI2017]Turysta

    4727: [POI2017]Turysta Time Limit: 20 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 117  Solved ...

  4. bzoj 4724 [POI2017]Podzielno 二分+模拟

    [POI2017]Podzielno Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 364  Solved: 160[Submit][Status][ ...

  5. BZOJ 4726: [POI2017]Sabota?

    4726: [POI2017]Sabota? Time Limit: 20 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 301  Solved ...

  6. BZOJ 4723: [POI2017]Flappy Bird

    Description 从一个点到一条直线,每次纵坐标只能增加或减少1,有些位置有障碍,求最少增加步数. Sol 贪心. 或许是贪心吧...反正在可到达的范围内,纵坐标尽量小... 做的时候维护一下两 ...

  7. BZOJ 4726: [POI2017]Sabota? 树形dp

    4726: [POI2017]Sabota? 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4726 Description 某个公司有n ...

  8. BZOJ.4727.[POI2017]Turysta(哈密顿路径/回路 竞赛图)

    题目链接 \(Description\) 给出一个n个点的有向图,任意两个点之间有且仅一条有向边.对于每个点v,求出从v出发的一条经过点数最多,且没有重复经过同一个点一次以上的简单路径. n<= ...

  9. bzoj 4723 [POI2017]Flappy Bird 模拟

    [POI2017]Flappy Bird Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 482  Solved: 196[Submit][Status ...

随机推荐

  1. bzoj 3163: [Heoi2013]Eden的新背包问题

    Description "寄没有地址的信,这样的情绪有种距离,你放着谁的歌曲,是怎样的心心静,能不能说给我听."失忆的Eden总想努力地回忆起过去,然而总是只能清晰地记得那种思念的 ...

  2. 如何查看SQL Server的版本、补丁包信息?以及如何鉴别是否需要升级自己的SQL Server?

    作为一个SQL Server的数据库管理人员,经常需要碰到的一个问题就是查看自己SQL Server属于哪个版本,是否安装了最新的修复补丁包,是否安装了最近的安全补丁.在此之前,我们可以通过以下SQL ...

  3. 一张图看懂git push

    基本用法 上面的四条命令在工作目录.暂存目录(也叫做索引)和仓库之间复制文件. git add files 把当前文件放入暂存区域. git commit 给暂存区域生成快照并提交. git rese ...

  4. Mvc中域的添加和不同域之间的跳转

    一.在新添加的域中中的 AreaRegistration中作如下设置: 二.在原来的Global.asax中设置: 三.不同域之间的跳转 @Url.Action("Index", ...

  5. opencv 比较直方图方式 进行人脸检测对比

    完整opencv(emgucv)人脸.检测.采集.识别.匹配.对比 //成对几何直方图匹配               public static string MatchHist()         ...

  6. 配置samba

    安装samba服务器之后,很方便的实现Windows和Linux进行通信. 安装步骤:1.在Ubuntu系统下面安装samba服务: nii@ww:~$ sudo apt-get install sa ...

  7. linux 下向github上传代码

    上传代码: cd TPS/devices/M8 git init                      #//初始化 git add .                    #如果是.表示上传全 ...

  8. Spring IoC容器的初始化过程

    Spring IoC容器的初始化包括 BeanDefinition的Resource定位.载入和注册 这三个基本的过程.IoC容器的初始化过程不包含Bean依赖注入的实现.Bean依赖的注入一般会发生 ...

  9. MySQL中日期与时间类型

    http://blog.sina.com.cn/s/blog_4d8730df01014jiy.html

  10. 10月28日上午 PHP数据访问

    1.建一个连接(连接PHP和MYSQL) $db = new MySQLi("localhost","root","666","t ...