5884. 【NOIP2018模拟A组9.25】蒲公英的约定(瞎搞)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq872425710/article/details/82865075

题目大意:

Step 1:首先把 c 和 lastans 按位异或得到 b,最开始 lastans 是 0
Step 2:如果这天的 b 等于 0,则说明他们已经长出了所有要长出的种子,哥哥与弟弟的交 流结束(输入文件也到此结束)
Step 3:如果这天的 b 不等于 0,弟弟会求出一个最小的非负整数 x 使得在这里插入图片描述 (即a^x同余于b模p),[题目保证可以找到这样的 x]
Step 4:lastans 赋值为 x

思路:

因为他没有要求强制在线,我们可以从后往前做,这样因为最后一个答案和最后一个c异或答案为0,这样就可以反推x,然后根据式子推出这一个的b,然后一直重复这样就可以推出所有的答案了。
这题还可以用BSGS做很高的部分分,我也不会…晚上问问大佬们,或者是log的离散对数做法。

程序:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#define N 100005
#define LL long long
using namespace std;
LL mo,n;
LL a[N],b[N],ans[N],c[N];

LL mul(LL x,LL y){
	if (y==1) return x;
	if (y==0) return 1;
	LL o=mul(x,y/2);
	o=(o*o)%mo;
	if (y%2==1) o=(o*x)%mo;
	return o;
}

int main(){
	freopen("dandelion.in","r",stdin);
	freopen("dandelion.out","w",stdout);
	scanf("%lld",&mo);
	n=1;
	while (~scanf("%lld%lld",&a[n],&b[n])) n++;
	n--;
	ans[n-1]=b[n];
	for (LL i=n-1;i>=1;i--){
		c[i]=mul(a[i],ans[i]);
		ans[i-1]=b[i] xor c[i];
	}
	for (LL i=1;i<n;i++) printf("%lld\n",ans[i]); 
}

猜你喜欢

转载自blog.csdn.net/qq872425710/article/details/82865075