题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFnoi%E8%80%83%E5%90%8E%E6%AC%A2%E4%B9%90%E8%B5%9B%29/%E9%9A%8F%E6%9C%BA%E6%95%B0%E7%94%9F%E6%88%90%E5%99%A8

题解:这题做的我也是醉了。。。

一阶递推然后还要翻转,那矩阵是不能做了。。。然后发现好像是不可做题。。。简要题解说是循环节?

如果出现以前出现过的显然可以输出ans了,可是模数这么大,如果模数只有100W的话很容易出现,20亿怎么保证会在不超时的情况下重复?

唉?我想到了什么?生日攻击!如果有23个人,那么他们中有同生日的概率超过50%。

然后在hash killer II中,有这样的结论:

生日攻击:如果你在n个数中随机选数,那么最多选√n次就能选到相同的数(不考虑Rp broken)

同样的,这题的Hash值在0到1000000007.

那就要选差不多10^5次

唯一注意的是l要取大,使得方案数超过Mod

否则就不可能有2个数有相同的Hash值

所以我们可以暴力模拟前面的直到出现重复。

代码:

 #include<cstdio>

 #include<cstdlib>

 #include<cmath>

 #include<cstring>

 #include<algorithm>

 #include<iostream>

 #include<vector>

 #include<map>

 #include<set>

 #include<queue>

 #include<string>

 #define inf 1000000000

 #define maxn 1000000+5

 #define maxm 500+100

 #define eps 1e-10

 #define ll long long

 #define pa pair<int,int>

 #define for0(i,n) for(int i=0;i<=(n);i++)

 #define for1(i,n) for(int i=1;i<=(n);i++)

 #define for2(i,x,y) for(int i=(x);i<=(y);i++)

 #define for3(i,x,y) for(int i=(x);i>=(y);i--)

 #define mod 1000000007

 using namespace std;

 inline ll read()

 {

     ll x=,f=;char ch=getchar();

     while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}

     while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}

     return x*f;

 }
int c[maxn];
map<ll,int>mp; int main() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); ll a=read(),b=read(),m=read(),x=read(),n=read();
for(ll i=;i<=n;i++)
{
ll y=(a*x+b)%m;x=;
for(;y;y/=)x=*x+y%;
x%=m;
y=mp[x];
if(y){printf("%d\n",c[y+(n-i+-)%(i--y+)+-]);return ;}else c[mp[x]=i]=x;
}
cout<<x<<endl; return ; }

Beta Round #9 (酱油杯noi考后欢乐赛)随机数生成器的更多相关文章

  1. Beta Round #9 (酱油杯noi考后欢乐赛)乌鸦喝水

    题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFno ...

  2. Beta Round #9 (酱油杯noi考后欢乐赛)PLQ和他的小伙伴们

    题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFno ...

  3. Beta Round #9 (酱油杯noi考后欢乐赛)PLQ的寻宝

    题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFno ...

  4. Beta Round #9 (酱油杯noi考后欢乐赛)最大伤害

    题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFno ...

  5. 洛谷---小L和小K的NOIP考后放松赛

    链接: https://www.luogu.org/contestnew/show/11805?tdsourcetag=s_pcqq_aiomsg 题解: 没人过的题我就没看 t2: 考虑每个点是朋友 ...

  6. Codeforces Beta Round #57 (Div. 2)

    Codeforces Beta Round #57 (Div. 2) http://codeforces.com/contest/61 A #include<bits/stdc++.h> ...

  7. Codeforces Beta Round #52 (Div. 2)

    Codeforces Beta Round #52 (Div. 2) http://codeforces.com/contest/56 A #include<bits/stdc++.h> ...

  8. Codeforces Beta Round #46 (Div. 2)

    Codeforces Beta Round #46 (Div. 2) http://codeforces.com/contest/49 A #include<bits/stdc++.h> ...

  9. Codeforces Beta Round #31 (Div. 2, Codeforces format)

    Codeforces Beta Round #31 (Div. 2, Codeforces format) http://codeforces.com/contest/31 A #include< ...

随机推荐

  1. IOS 高级开发 runtime(二)

    二.移魂大法 使用runtime还可以交换两个函数.先贴上代码和执行结果. #import <Foundation/Foundation.h> @interface DZLPerson : ...

  2. nginx图片服务器配置

    worker_processes ; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/erro ...

  3. Java工具类:获取long型唯一ID

    直接上代码: import java.text.SimpleDateFormat; import java.util.Date; /** * 获取long型唯一ID */ public class I ...

  4. 理解Java中的前期绑定和后期绑定

    前期绑定,在程序执行前根据编译时类型绑定,调用开销较小,如C语言只有前期绑定这种方法调用. 后期绑定,是指在运行时根据对象的类型进行绑定,又叫动态绑定或运行时绑定.实现后期绑定,需要某种机制支持,以便 ...

  5. 【转】Oracle job procedure 存储过程定时任务

    原文:Oracle job procedure 存储过程定时任务 oracle job有定时执行的功能,可以在指定的时间点或每天的某个时间点自行执行任务. 一.查询系统中的job,可以查询视图 --相 ...

  6. React组件二

    <script type="text/babel"> <!-- this.props.children表示读取组件的所有子节点-->var Zu=React ...

  7. Python的面向对象3

    接下来,我们接着讲Python的面向对象,在上一次的博客中,我们详细介绍了类与对象的属性,今天,我们来详细介绍一下面向对象中的方法! 1.定义实例方法 一个实例的私有属性就是以__开头的属性,无法被外 ...

  8. python【第十八篇】Django基础

    1.什么是Django? Django是一个Python写成的开源Web应用框架.python流行的web框架还有很多,如tornado.flask.web.py等.django采用了MVC的框架模式 ...

  9. 解决vsftpd 2.2.2读取目录列表失败的问题

    该错误是由iptables的配置引起的,临时的解决方法是执行如下命令: [root@localhost soft]# modprobe ip_nat_ftp 再次登陆列表正常啦! 但当你重新启动服务器 ...

  10. [置顶] Android Journal

    ==================================================================================================== ...