题意:

给出四个数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的更多相关文章

  1. 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- ...

  2. UVA 10090 Marbles 扩展欧几里得

    来源:http://www.cnblogs.com/zxhl/p/5106678.html 大致题意:给你n个球,给你两种盒子.第一种盒子每个盒子c1美元,可以恰好装n1个球:第二种盒子每个盒子c2元 ...

  3. 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 ...

  4. UVA 12169 Disgruntled Judge 扩展欧几里得

    /** 题目:UVA 12169 Disgruntled Judge 链接:https://vjudge.net/problem/UVA-12169 题意:原题 思路: a,b范围都在10000以内. ...

  5. [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 ...

  6. UVA 10673 扩展欧几里得

    题意:给出x 和k,求解p和q使得等式x = p[x / k] + q [ x / k], 两个[x / k]分别为向下取整和向上取整 题解:扩展欧几里得 //meek///#include<b ...

  7. UVA 10090 Marbles(扩展欧几里得)

    Marbles Input: standard input Output: standard output I have some (say, n) marbles (small glass ball ...

  8. UVa 11768 格点判定(扩展欧几里得求线段整点)

    https://vjudge.net/problem/UVA-11768 题意: 给定两个点A(x1,y1)和B(x2,y2),均为0.1的整数倍.统计选段AB穿过多少个整点. 思路: 做了这道题之后 ...

  9. 【扩展欧几里得】BAPC2014 I Interesting Integers (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

随机推荐

  1. 巨大bug

    //数据结构关于课程设计--------图书馆管理系统的设计 #include <stdio.h> #include <stdlib.h> #include <strin ...

  2. 2186: [Sdoi2008]沙拉公主的困惑 - BZOJ

    Description 大富翁国因为通货膨胀,以及假钞泛滥,政府决定推出一项新的政策:现有钞票编号范围为1到N的阶乘,但是,政府只发行编号与M!互质的钞票.房地产第一大户沙拉公主决定预测一下大富翁国现 ...

  3. 3139:[HNOI2013]比赛 - BZOJ

    题目描述 Description 沫沫非常喜欢看足球赛,但因为沉迷于射箭游戏,错过了最近的一次足球联赛.此次联赛共N只队伍参加,比赛规则如下: (1) 每两支球队之间踢一场比赛. (2) 若平局,两支 ...

  4. SpringJUnit4测试--测试无反应/控制台报空指针的解决---junit的jar冲突!

    前言: 前些日子碰到一个诡异的问题--用springJUnit进行测试,运行方法什么反应也没有,控制台 也没有输出,百度也没有答案--只好暂时作罢.今天我只好用上了排除法,建个测试小项目,将只要能测试 ...

  5. 在一个长度为n的数组里的所有数字都在0到n-1的范围内。 数组中某些数字是重复的,但不知道有几个数字是重复的。也不知道每个数字重复几次。请找出数组中任意一个重复的数字。 例如,如果输入长度为7的数组{2,3,1,0,2,5,3},那么对应的输出是重复的数字2或者3

    // test14.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...

  6. C# 读取枚举描述信息实例

    using System;using System.Collections;using System.Collections.Generic;using System.Linq;using Syste ...

  7. 导入 github 步骤

    https://github.com/dotnet/corefx       如果出现未能找到解决方案的情况,则找项目文件打开,如:  

  8. Microsoft SQLServer有四种系统数据库

    Microsoft SQLServer有四种系统数据库: 1.master数据库 master数据库记录SQLServer系统的所有系统级别信息.它记录所有的登录帐户和系统配置设置.master数据库 ...

  9. sampler2d

    Here is the syntax for a sampler in Direct3D 9. sampler Name = SamplerType{   Texture = <texture_ ...

  10. [设计模式] 5 单例模式 singleton

    转处 http://blog.csdn.net/wuzhekai1985 软件领域中的设计模式为开发人员提供了一种使用专家设计经验的有效途径.设计模式中运用了面向对象编程语言的重要特性:封装.继承.多 ...