UVa 12169 (枚举+扩展欧几里得) Disgruntled Judge
题意:
给出四个数T, a, b, x1,按公式生成序列 xi = (a*xi-1 + b) % 10001 (2 ≤ i ≤ 2T)
给出T和奇数项xi,输出偶数项xi
分析:
最简单的办法就是直接枚举a、b,看看与输入是否相符。
#include <cstdio> const int maxn = + ;
const int M = ;
int T, x[maxn]; int main()
{
//freopen("12169in.txt", "r", stdin); scanf("%d", &T);
for(int i = ; i < *T; i += )
scanf("%d", &x[i]); bool ok;
for(int a = ; a < M; ++a)
{
for(int b = ; b < M; ++b)
{
ok = true;
for(int i = ; i <= *T; i += )
{
x[i] = (x[i-]*a + b) % M;
if(i < *T && x[i+] != (x[i]*a + b) % M)
{
ok = false;
break;
}
}
if(ok) break;
}
if(ok) break;
} for(int i = ; i <= *T; i += )
printf("%d\n", x[i]); return ;
}
代码君
第二种办法枚举a,根据x1、x3求b。
详见这里
#include <cstdio> typedef long long LL;
const int maxn = + ;
const LL M = ;
int T;
LL x[maxn]; void gcd(LL a, LL b, LL& d, LL& x, LL& y)
{
if(!b) { d = a; x = ; y = ; }
else { gcd(b, a%b, d, y, x); y -= x*(a/b); }
} int main()
{
//freopen("12169in.txt", "r", stdin); scanf("%d", &T);
for(int i = ; i < *T; i += )
scanf("%lld", &x[i]); bool ok;
for(LL a = ; a < M; ++a)
{
LL t = x[] - a*a*x[];
LL g, k, b;
gcd(a+, M, g, b, k);
if(t % g != ) continue;
b *= t / g; ok = true;
for(int i = ; i <= *T; i += )
{
x[i] = (x[i-]*a+b) % M;
if(i < *T && x[i+] != (x[i]*a+b) % M)
{
ok = false;
break;
}
}
if(ok) break;
} for(int i = ; i <= *T; i += )
printf("%lld\n", x[i]); return ;
}
代码君
UVa 12169 (枚举+扩展欧几里得) Disgruntled Judge的更多相关文章
- 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 扩展欧几里得
来源:http://www.cnblogs.com/zxhl/p/5106678.html 大致题意:给你n个球,给你两种盒子.第一种盒子每个盒子c1美元,可以恰好装n1个球:第二种盒子每个盒子c2元 ...
- Codeforces Round #451 (Div. 2) B. Proper Nutrition【枚举/扩展欧几里得/给你n问有没有两个非负整数x,y满足x·a + y·b = n】
B. Proper Nutrition time limit per test 1 second memory limit per test 256 megabytes input standard ...
- UVA 12169 Disgruntled Judge 扩展欧几里得
/** 题目:UVA 12169 Disgruntled Judge 链接:https://vjudge.net/problem/UVA-12169 题意:原题 思路: a,b范围都在10000以内. ...
- [codeforces 200 E Tractor College]枚举,扩展欧几里得,三分
题目出自 Codeforces Round #126 (Div. 2) 的E. 题意大致如下:给定a,b,c,s,求三个非负整数x,y,z,满足0<=x<=y<=z,ax+by+cz ...
- UVA 10673 扩展欧几里得
题意:给出x 和k,求解p和q使得等式x = p[x / k] + q [ x / k], 两个[x / k]分别为向下取整和向上取整 题解:扩展欧几里得 //meek///#include<b ...
- UVA 10090 Marbles(扩展欧几里得)
Marbles Input: standard input Output: standard output I have some (say, n) marbles (small glass ball ...
- UVa 11768 格点判定(扩展欧几里得求线段整点)
https://vjudge.net/problem/UVA-11768 题意: 给定两个点A(x1,y1)和B(x2,y2),均为0.1的整数倍.统计选段AB穿过多少个整点. 思路: 做了这道题之后 ...
- 【扩展欧几里得】BAPC2014 I Interesting Integers (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
随机推荐
- 从OGRE,GAMEPLAY3D,COCOS2D-X看开源
OGRE,大家都很熟悉咯. 说到这一点真的有点好笑,我见过很多人说认识OGRE,但是却不知道D3D和OPENGL是什么东东的,可能是我的笑点真的很低,反正是莫名喜感.前天在COCOS2D-X的一个群里 ...
- 本地虚拟机中匿名ftp上传文件失败的问题
在10.10.50.230中新建了一个匿名的ftp服务器,结果在10.10.50.241中上传文件时提示: local: README.txt remote: /var/ftp/pub/upload ...
- Jsonp 前后端交互操作
今天,因为项目的需要,研究了一下JSONP,特在此记录一下 ,希望可以帮助那些有疑惑的朋友们,本人也是刚学,高手略过即可. 关于Jsonp的定义就不说了,网上一片,大家可以自己查询.我就在此直接进入正 ...
- [转载]DirectoryEntry配置IIS7出现ADSI Error:未知错误(0x80005000)
一.错误情况 环境:win7+iis7.0 DirectoryEntry配置IIS7出现如下错误 或者是 下面一段代码在IIS6.0下运转正常,但IIS7.0下运转会出错: System.Direct ...
- C++ Variables and Basic Types Notes
1. Type conversion: If we assign an out-of-range value to an object of unsigned type, the result is ...
- Javascript 选项卡
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- C# Regex类用法
使用Regex类需要引用命名空间:using System.Text.RegularExpressions; 利用Regex类实现全部匹配输出 string str = "test43232 ...
- Project Euler 92:Square digit chains 平方数字链
题目 Square digit chains A number chain is created by continuously adding the square of the digits in ...
- *[codility]Country network
https://codility.com/programmers/challenges/fluorum2014 http://www.51nod.com/onlineJudge/questionCod ...
- [Unity菜鸟] Final IK
由于本人英文较烂,边翻译用户手册边学习. 用户手册 IK Components Final IK 包含许多强大高速的IK组件 Aim AimIK solver是一个对CCD算法(cyclic co ...