题目链接:

  https://vijos.org/p/1472

题目大意

  S1={1,2,3…n}。当i>1时,Si为集合Si-1中任意两个不相同数之和的集合。

  将每个集合中所有元素取出,集合Si的数放在集合Si+1的数的前面,同一个集合数从小到大排序,这样得到一个序列L。

  题目输入n和K,求L中第K个数是多少。

  变态的数据范围:K≤101000,1<n≤1000;且数据保证当n≤3时,K≤900000。

题目思路:

  【二分】【高精度】

  真是恶心的一道题啊。。打了好久。

  S1={1,2,...,n}

  S2={3,4,...,2n-1}

  S3={7,8,...,4n-3}

  S4={15,16,...,8n-7}

  S5={31,32,...,16n-15}

  ......

  Sk={2k-1,2k,...,n*2k-1-2k-1+1}={2k-1,2k,...,(n-1)2k-1+1}

  所以第k个集合的大小为(n-1)*2k-1-2k+3

  前k个集合总数为(n-3)*2k+3(k+1)-n

  二分目标数处在第几个集合,然后简单运算并输出即可。注意n=1,2,3的情况。

 //
//by coolxxx
//
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define eps 1e-8
#define J 10000000
#define MAX 0x7f7f7f7f
#define PI 3.1415926535897
#define N 1007
#define M 10007
using namespace std;
typedef long long LL;
int cas,cass;
int n,m,lll,ans;
LL k[M];
char ch[N];
void gjdprint(LL a[])
{
int i;
printf("%lld",a[a[]]);
for(i=a[]-;i;i--)
printf("%07lld",a[i]);
puts("");
}
int gjdcompare(LL a[],LL b[])//-1:a=b 0:a<b 1:a>b
{
int i;
if(a[]!=b[])return a[]>b[];
for(i=a[];i;i--)
if(a[i]!=b[i])return a[i]>b[i];
return -;
}
void gjdcheng(LL a[],LL b[],LL c[])
{
LL t[M]={};
int i,j;
t[]=a[]+b[];
for(i=;i<=a[];i++)
for(j=;j<=b[];j++)
t[i+j-]+=a[i]*b[j];
for(i=;i<=t[];i++)
t[i+]+=t[i]/J,t[i]%=J;
while(t[t[]+])t[]++;
while(!t[t[]] && t[]>)t[]--;
memcpy(c,t,sizeof(t));
}
void gjdquickpow(LL a[],LL x)
{
LL t[M]={,,};
a[]=a[]=;
while(x)
{
if(x&)
{
gjdcheng(a,t,a);
}
gjdcheng(t,t,t);
x>>=;
}
}
void gjdchange(char s[],LL a[])
{
int i,j,l;
l=strlen(s);
for(i=l,a[]=;i>;i-=,a[]++)
{
for(j=;j<;j++)
a[a[]]=a[a[]]*+s[i-+j]-'';
}
for(j=;j<i;j++)
a[a[]]=a[a[]]*+s[j]-'';
}
void gjdjia(LL a[],LL b[],LL c[])
{
int i;
LL t[M]={};
t[]=max(a[],b[]);
for(i=;i<=t[];i++)
t[i]=a[i]+b[i];
for(i=;i<=t[];i++)
t[i+]+=t[i]/J,t[i]%=J;
while(t[t[]+])t[]++;
while(!t[t[]] && t[]>)t[]--;
memcpy(c,t,sizeof(t));
}
void gjdjian(LL a[],LL b[],LL c[])
{
int i;
LL t[M]={};
t[]=a[];
for(i=;i<=t[];i++)
t[i]=a[i]-b[i];
for(i=;i<t[];i++)
if(t[i]<)t[i+]--,t[i]+=J;
while(!t[t[]] && t[]>)t[]--;
memcpy(c,t,sizeof(t));
}
void gjdchu2(LL a[])
{
int i;
for(i=a[];i>;i--)
{
if(a[i]&)a[i-]+=J;
a[i]>>=;
}
a[]>>=;
while(!a[a[]] && a[]>)a[]--;
}
void getsum(LL t[],LL mid,LL tt[])
{
gjdquickpow(t,mid-);
tt[]=n-;
gjdcheng(t,tt,t);
tt[]=mid*;
gjdjia(t,tt,t);
tt[]=n;
gjdjian(t,tt,t);
}
void work()
{
int i,j,l,r,mid;
LL t[M]={},tt[M]={,};
l=;r=;
while(l<r)
{
mid=(l+r+)>>;
getsum(t,mid,tt);
j=gjdcompare(k,t);
if(j==-)
{
gjdquickpow(t,mid-);
tt[]=n-;
gjdcheng(t,tt,t);
tt[]=;
gjdjia(t,tt,t);
gjdprint(t);
return;
}
if(j)l=mid;
else r=mid-;
}
getsum(t,r,tt);
gjdjian(k,t,k);
gjdquickpow(t,r);
tt[]=;
gjdjian(t,tt,t);
gjdjia(k,t,t);
gjdprint(t);
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j;
// while(~scanf("%s",s1))
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
while(~scanf("%d",&n))
{
memset(k,,sizeof(k));
if(n<)
{
scanf("%d",&m);
if(n==)
{
if(m==)puts("");
else puts("-1");
}
else if(n==)
{
if(m==)puts("");
else if(m==)puts("");
else if(m==)puts("");
else puts("-1");
}
else if(n==)
{
gjdquickpow(k,(m+)/);
if(m%==)k[]--;
else if(m%==)k[]++;
gjdprint(k);
}
continue;
}
scanf("%s",ch);
gjdchange(ch,k);
if(k[]== && k[]<=n)
{
gjdprint(k);
continue;
}
work();
}
return ;
} /*
// //
*/

千万不要点

【二分】【高精度】Vijos P1472 教主的集合序列的更多相关文章

  1. POJ-2109 Power of Cryptography(数学或二分+高精度)

    题目链接: https://vjudge.net/problem/POJ-2109 题目大意: 有指数函数 k^n = p , 其中k.n.p均为整数且 1<=k<=10^9 , 1< ...

  2. List集合序列排序的两种方法

    首先讲一下Comparable接口和Comparator接口,以及他们之间的差异.有助于Collections.sort()方法的使用.请参考 1.Comparable自然规则排序//在自定义类Stu ...

  3. 高精度处理斐波那契序列(C语言)

    #include<stdio.h> #include<string.h> //memset,strcpy,strlen函数头文件 int main(void) { ];//用来 ...

  4. python——序列 & 集合 & 映射

    列表 & 元组 & 字典 & 集合 序列 序列: 每个元素可以是任何类型(也可以是序列),每个元素被分配一个序号(从0开始)(序号,也叫索引,表示元素的位置) Python中的 ...

  5. BZOJ_3343_教主的魔法_分块+二分查找

    BZOJ_3343_教主的魔法_分块+二分查找 题意:教主最近学会了一种神奇的魔法,能够使人长高.于是他准备演示给XMYZ信息组每个英雄看.于是N个英雄们又一次聚集在了一起,这次他们排成了一列被编号为 ...

  6. poj 1064 高精度 二分

    Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 32191 Accepted: 6888 Descrip ...

  7. 『无为则无心』Python序列 — 22、Python集合及其常用操作

    目录 1.Python集合特点 2.Python集合的创建 3.操作集合常用API (1)增加数据 @1.add()方法 @2.update()方法 (2)删除数据 @1.remove()方法 @2. ...

  8. 流畅的python python 序列

    内置序列 容器类型 list .tuple和collections.deque这些序列能放入不同的类型的数据 扁平序列 str.byets.bytearray.memoryview(内存视图)和arr ...

  9. Codeforces 939E Maximize ( 三分 || 二分 )

    题意 : 给出两个操作,① 往一个序列集合(初始为空)里面不降序地添加数字.② 找出当前序列集合的一个子集使得 (子集的最大元素) - (子集的平均数) 最大并且输出这个最大差值 分析 :  首先关注 ...

随机推荐

  1. Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.(转)

    1.程序运行后异常显示: 解决方案:在项目上点击右键->properties->Java Build Path, remove掉Android Dependences即可

  2. 模板-->常系数线性齐次递推(矩阵快速幂)

    如果有相应的OJ题目,欢迎同学们提供相应的链接 相关链接 所有模板的快速链接 Matrix模板 poj_2118_Firepersons,my_ac_code 简单的测试 None 代码模板 /* * ...

  3. 模板-->Guass消元法(求解多元一次方程组)

    如果有相应的OJ题目,欢迎同学们提供相应的链接 相关链接 所有模板的快速链接 简单的测试 None 代码模板 /* * TIME COMPLEXITY:O(n^3) * PARAMS: * a The ...

  4. 最小圆覆盖 hdu 3007

    今天学习了一下最小圆覆盖, 看了一下午都没看懂, 晚上慢慢的摸索这代码,接合着别人的讲解, 画着图跟着代码一步一步的走着,竟然有些理解了. 最小圆覆盖: 给定n个点, 求出半径最小的圆可以把这些点全部 ...

  5. python字符串replace()方法

    python字符串replace()方法 >>> help(str.replace)Help on method_descriptor:replace(...)    S.repla ...

  6. SpringMVC12拦截器

    创建登陆界面 <%@ page language="java" import="java.util.*" pageEncoding="utf-8 ...

  7. Linux安装配置mongodb

    1. 下载MongoDB 2. 解压文件到某目录下,然后重命名: [root@localhost var]# tar -xzvf mongodb-linux-i686-2.0.1.tar [root@ ...

  8. hdu1102 Constructing Roads (简单最小生成树Prim算法)

    Problem Description There are N villages, which are numbered from 1 to N, and you should build some ...

  9. css实现鼠标移入table时出现滚动条且table内容不移位

    一般是这样: 表格的标题和内容分别由一个table组成,其中表格内容的table由一个class="table-body"的div包裹.css如下 .tContainer .tab ...

  10. extjs中combobox默认显示第一个值

    在进入页面时往往用户希望页面能够显示默认的内容,但是页面中会存在一些选项通过用户选择之后才会加载相应的内容.在这篇文章里面介绍了如何去设置页面中默认的内容,如combobox默认显示第一个值. 页面: ...