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

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

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

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

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=2∗10143^{30}=2*10^{14}330=21014
而打表打出来其实是这样一个段的长度

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

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

Update:Update:Update:

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

#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<<'\n';break;}
		}
	}
}

转载于:https://www.cnblogs.com/stargazer-cyk/p/11145556.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值