【SCOI2019】—DAY1T1平台跳跃(打表+高精度)

太菜了只做出来了T1
口胡一下题解刷一波访问量

可以发现显然ii个球的答案f[i]=f[i1]3+(n1)f[i]=f[i-1]*3+(n-1)
但是m=1000m=1000高精度5002q500^2*q也过不去

我们可以打表第ii步的答案
会发现显然连续的一段都是同一个答案
而且是这样的

1 1 1 1 1 ....
2 2 2 ....
1 1 1 1 1....
2 2 2 ....
1 1 1 1 1....
2 2 2 ....
1 1 1 1 1....
3 3 3.....

最后会发现规律是这样的

答案为1的时候是第奇数行
答案为2的时候是行为2的倍数且不为6的倍数
答案为3的时候是行为6的倍数且不为18的倍数
答案为4的时候是行为18的倍数且不为54的倍数
答案为5的时候是行为54的倍数且不为162的倍数
……
由于题目里面保证了答案在30以内
330=210143^{30}=2*10^{14}
而打表打出来其实是这样一个段的长度

n-1
k-1
n-1
n-k
……

所以我们就可以很方便的找出来qq是第几段
高精除低精就可以了
然后做一个高精取模就完了
而这两个都可以做到O(len)O(len)
总复杂度O(qlen30)O(q*len*30)

Update:Update:

突然发现自己暴力打挂了QAQQAQ

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
inline int read(){
	char ch=getchar();
	int res=0;
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=getchar();
	return res;
}
int n,m,k,q,del,fi,se,thr;
ll f[35];
struct Bignum{
	int a[505],n;
	Bignum(){
		n=0,memset(a,0,sizeof(a));
	}
	friend inline Bignum operator +(const Bignum &a,const Bignum &b){
		Bignum c;c.n=max(a.n,b.n);
		for(re int i=1;i<=c.n;++i){
			c.a[i]+=a.a[i]+b.a[i];
			if(c.a[i]>=10)c.a[i]-=10,++c.a[i+1];
		}
		if(c.a[c.n+1])++c.n;
		return c;
	}
	friend inline Bignum operator /(const Bignum &a,const ll &b){
		ll res=0;Bignum c;c.n=a.n;
		for(re int i=c.n;i;--i){
			res=res*10+a.a[i];
			if(res>=b)c.a[i]=res/b,res=res-(res/b)*b;
		}
		while(c.n&&!c.a[c.n])--c.n;
		return c;
	}
	friend inline int operator %(const Bignum &a,const ll b){
		ll res=0;
		for(re int i=a.n;i;--i){
			res=res*10+a.a[i];
			if(res>=b)res=res-(res/b)*b;
		}
		return res;
	}
	inline void read(){
		char ch=getchar();
		while(!isdigit(ch))ch=getchar();
		while(isdigit(ch))
			a[++n]=ch^48,ch=getchar();
		reverse(a+1,a+n+1);
	}
}one,two,three;
signed main(){
	n=read(),m=read(),k=read(),q=read();
	f[1]=1,f[2]=2,del=3*n-3;
	for(int i=3;i<=30;i++)f[i]=f[i-1]*3ll;
	one.n=1,two.n=1,three.n=1,one.a[1]=1,two.a[1]=2,three.a[1]=3;
	while(q--){
		Bignum p;p.read();
		ll res=p%del;
		p=p/del,p=p+p,p=p+p;
		if(res>0)p=p+one;
		if(res>n-1)p=p+one;
		if(res>n-1+k-1)p=p+one;
		if(res>n-1+k-1+n-1)p=p+one;
		for(re int i=0;i<=29;i++){
			if(p%f[i+1]!=0){cout<<i<<'
';break;}
		}
	}
}
原文地址:https://www.cnblogs.com/stargazer-cyk/p/11145556.html