题目链接:

  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. [PWA] 6. Hijacking response

    For example, if the url is not match to any API endpoint, we want to return 404 error message. So fi ...

  2. PHP安全编程:会话数据注入 比会话劫持更强大的攻击(转)

    一个与会话暴露类似的问题是会话注入.此类攻击是基于你的WEB服务器除了对会话存储目录有读取权限外,还有写入权限.因此,存在着编写一段允许其他用户添加,编辑或删除会话的脚本的可能.下例显示了一个允许用户 ...

  3. Codeforces Round #258 (Div. 2)[ABCD]

    Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意 ...

  4. linux 下 apt命令集详解

    apt命令用法 packagename指代为软件包的名称 apt-get update 在修改/etc/apt/sources.list或/etc/apt/preferences之後运行该命令.此外您 ...

  5. noip 2012 国王游戏(贪心+高精)

    /* 我是不会说我考试的时候想到了正解却把金币取大看成金币求和的.... 觉得只按左右手乘积排序不太对 有反例 也可能我反例放到这个题里是错的吧 按自己的理解排的序 就是各种讨论... 假设 第i个人 ...

  6. visual studio中的一些实用的快捷键

    重置开发环境:使得开发工具恢复默认状态 方法:工具->导入和导出设置导向->重置所有设置->不保存 显示行号: 方法:工具->选项->所有语言->行号 在编程过程中 ...

  7. C#实现发送邮件

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  8. shareSDK微博分享出现: 分享失败: 错误描述:Insufficient app permissions! 错误码:10014

    这个错误是由于appKey所在账号没有微博高级写入接口权限, 需要申请, 详见: http://www.mamicode.com/info-detail-936938.html

  9. Eclipse怎么忽略掉报错的js文件

    第一步,我们要先定位错误在哪里,选择菜单里window——show view——other,选择Problems. 第二步,点击有红叉的项目,在Problems视图中,可以看到是什么错,哪个文件夹中的 ...

  10. POJ3185 The Water Bowls(反转法or dfs 爆搜)

    POJ3185 The Water Bowls 题目大意: 奶牛有20只碗摆成一排,用鼻子顶某只碗的话,包括左右两只在内的一共三只碗会反向,现在给出碗的初始状态,问至少要用鼻子顶多少次才能使所有碗都朝 ...