UVA 12169 Disgruntled Judge 扩展欧几里得
/**
题目:UVA 12169 Disgruntled Judge
链接:https://vjudge.net/problem/UVA-12169
题意:原题
思路:
a,b范围都在10000以内。暴力枚举1e8;但是还要判断。所以时间不够。 如果可以枚举a,然后算出b,再判断可行性,那么时间上是可行的。但是是多次方的方程无法解。 想其他办法:
xi = (a*xi-1 + b) % 10001 xi+1 = (a*xi+b)%10001 xi+2 = (a*xi+1+b)%10001 => xi+2 = a*(a*xi+b)+b % 10001
= a*a*xi + (a+1)*b % 10001 xi+2 = a*a*xi + (a+1)*b - 10001*k ; 扩展欧几里得求解b。 (a+1)*b - 10001*k = xi+2 - a*a*xi; 因为mod=10001所以,求出任意一个解即可。 哪怕b是负数,+一个mod也是可以变成非负数的。 a*x + b*y = c; c%gcd(a,b)==0; a*1 + b*0 = a; */ #include <iostream>
#include <cstdio> using namespace std;
typedef long long ll;
const int maxn = 1e4+;
ll c[maxn];
int T;
const int mod = 1e4+;
void ext_gcd(ll a,ll b,ll &d,ll &x,ll &y)
{
if(!b) {d = a; x = ; y = ;}
else{
ext_gcd(b,a%b,d,y,x); y = y-x*(a/b);
}
}
bool judge(ll a,ll b)
{
for(int i = ; i < T; i++){
ll t = (a*a*c[i-] + (a+)*b+mod) % mod;
if(t!=c[i]) return false;
}
return true;
}
int main()
{
//freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
//freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
while(scanf("%d",&T)==)
{
for(int i = ; i < T; i++){
scanf("%lld",&c[i]);
}
if(T==){
printf("0\n");
continue;
}
ll a, b, d, x, y;
for(int i = ; i < T; i++){
for(a = ; a < mod; a++){
ll temp = c[i]-a*a*c[i-];
ext_gcd(a+,mod,d,x,y);
b = x*(temp/d);
if(b<) b+= mod;
if(judge(a,b)){
break;
}
}
}
for(int i = ; i < T; i++){
printf("%lld\n",(a*c[i]+b+mod)%mod);
}
}
return ;
}
UVA 12169 Disgruntled Judge 扩展欧几里得的更多相关文章
- UVA.12169 Disgruntled Judge ( 拓展欧几里得 )
UVA.12169 Disgruntled Judge ( 拓展欧几里得 ) 题意分析 给出T个数字,x1,x3--x2T-1.并且我们知道这x1,x2,x3,x4--x2T之间满足xi = (a * ...
- UVA 12169 Disgruntled Judge 枚举+扩展欧几里得
题目大意:有3个整数 x[1], a, b 满足递推式x[i]=(a*x[i-1]+b)mod 10001.由这个递推式计算出了长度为2T的数列,现在要求输入x[1],x[3],......x[2T- ...
- UVA 10090 Marbles(扩展欧几里得)
Marbles Input: standard input Output: standard output I have some (say, n) marbles (small glass ball ...
- UVa 12169 Disgruntled Judge 紫书
思路还是按照紫书,枚举a,得出b, 然后验证. 代码参考了LRJ的. #include <cstdio> #include <iostream> using namespace ...
- UVA 12169 Disgruntled Judge【扩展欧几里德】
题意:随机选取x1,a,b,根据公式xi=(a*xi-1+b)%10001得到一个长度为2*n的序列,奇数项作为输入,求偶数项,若有多种,随机输出一组答案. 思路:a和b均未知,可以考虑枚举a和b,时 ...
- UVa 12169 - Disgruntled Judge(拓展欧几里德)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 12169 Disgruntled Judge(Extended_Euclid)
用扩展欧几里德Extended_Euclid解线性模方程,思路在注释里面了. 注意数据范围不要爆int了. /********************************************* ...
- UVA 12169 Disgruntled Judge
我该怎么说这道题呢...说简单其实也简单,就枚举模拟,开始卡了好久,今天看到这题没a又写了遍,看似会超时的代码交上去a了,果然实践是检验真理的唯一标准... #include <iostream ...
- hdu 2769 uva 12169 Disgruntled Judge 拓展欧几里德
//数据是有多水 连 10^10的枚举都能过 关于拓展欧几里德:大概就是x1=y2,y1=x2-[a/b]y2,按这个规律递归到gcd(a,0)的形式,此时公因数为a,方程也变为a*x+0*y=gcd ...
随机推荐
- asp.net mvc视图引擎
继上周介绍了Razor之后,ASP.NET MVC 现在已有四种主要的视图引擎.其他三种引擎是Spark.NHaml和传统的ASPX文件模板.本文将大致介绍这四种引擎,并着重讨论新的Razor引 擎. ...
- Coherence的集群成员的离开和加入机制研究
最近在客户那里环境中coherence集群不稳定,所以找出一些文档,需要搞清楚Coherence内部的一些机制 1.集群成员的离开 关于状态的检测,官方的说法是: Death detection is ...
- http://www.360doc.com/content/12/0516/14/1671317_211422841.shtml
http://www.360doc.com/content/12/0516/14/1671317_211422841.shtml
- 一起來玩鳥 Starling Framework(8)BitmapFont
所謂BitmapFont,就是事先將我們會用到的字型,會用到的字,輸出成一張圖片,類似Sprite sheet,以及一個xml格式的Data file,然後我們一次將這文字圖片轉成Texture,up ...
- Mounting the NFS share on a Windows server
今天遇到一个相当奇怪的问题,在windows 上mount LINUX NFS, powershell 脚本可以成功, 用图形界面也可以成功,但BATCH就是不行.提示53网络错误. 不过公司已经有人 ...
- 【codeforces #282(div 1)】AB题解
A. Treasure time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- 2014ACM/ICPC亚洲区域赛牡丹江站现场赛-A ( ZOJ 3819 ) Average Score
Average Score Time Limit: 2 Seconds Memory Limit: 65536 KB Bob is a freshman in Marjar Universi ...
- Django——WEB三层架构与MVC
而我发此文的目的有二:一者,让初学者能够听到一家之言,是为解惑:二者,更希望抛砖引玉,得到专家的批判. 许多学生经常问我,MVC到底和WEB三层架构有啥关系? 开始时,我也只能给他们一些模糊的回答.时 ...
- Srping AOP xml方式
使用aop需要: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="ht ...
- C语言文件操作函数大全(超详细)
C语言文件操作函数大全(超详细) 作者: 字体:[增加 减小] 类型:转载 本篇文章是对C语言中的文件操作函数进行了详细的总结分析,需要的朋友参考下 fopen(打开文件)相关函数 open,fc ...