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%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考后欢乐赛)随机数生成器的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 洛谷---小L和小K的NOIP考后放松赛
链接: https://www.luogu.org/contestnew/show/11805?tdsourcetag=s_pcqq_aiomsg 题解: 没人过的题我就没看 t2: 考虑每个点是朋友 ...
- Codeforces Beta Round #57 (Div. 2)
Codeforces Beta Round #57 (Div. 2) http://codeforces.com/contest/61 A #include<bits/stdc++.h> ...
- Codeforces Beta Round #52 (Div. 2)
Codeforces Beta Round #52 (Div. 2) http://codeforces.com/contest/56 A #include<bits/stdc++.h> ...
- Codeforces Beta Round #46 (Div. 2)
Codeforces Beta Round #46 (Div. 2) http://codeforces.com/contest/49 A #include<bits/stdc++.h> ...
- Codeforces Beta Round #31 (Div. 2, Codeforces format)
Codeforces Beta Round #31 (Div. 2, Codeforces format) http://codeforces.com/contest/31 A #include< ...
随机推荐
- 使用PDO连接多种数据库
在PHP 5之前,想要连接MySQL数据库就需要使用mysql或mysqli等一系列函数来操作数据库.例如,我们使用mysql系列数据库函数进行查询操作,对应的示例代码如下: <?php //创 ...
- 有理数类 Java
public class Rational extends Number implements Comparable { private long numerator;// 分子 private lo ...
- linux关闭声音
对于CentOS/Redhat/RHEL/Fedora系统,使用root身份执行:echo "alias pcspkr off" >> /etc/modprobe.co ...
- 如何理解systemstate
什么是systemstate一个systemstate是由在实例中调用生成systemstats时由每一个进程的进程状态组成.而每一个进程状态是由每一个进程所持有的当前对象所对应的详细对象状态信息组成 ...
- Struts2 多文件下载
Step1:导入支持jar包 commons-fileupload-1.3.1.jar commons-io-2.4.jar jstl-1.2.jar standard-1.1.2.jar commo ...
- javascript Window对象 第16节
<html> <head> <title>浏览器对象</title> <script type="text/javascript&quo ...
- spring Aop 注解
个人理解: spring Aop 是什么:面向切面编程,类似于自定义拦截操作,支持拦截之前操作@Before,拦截之后操作@After,拦截环绕操作@Around. 什么情况下使用spring Aop ...
- Git for Windows
本篇文章由:http://www.sollyu.com/git-for-windows/ 说明 Git是用于Linux内核开发的版本控制工具.与CVS.Subversion一类的集中式版本控制工具不同 ...
- MySQL存储引擎,优化,事务
1唯一约束unique和主键key的区别? 1.什么是数据的存储引擎? 存储引擎就是如何存储数据.如何为存储的数据建立索引和如何更新.查询数据等技术的实现方法.因为在关系数据库中数 ...
- demo_07选择器练习
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...