Uva 12169 不爽的裁判 模运算

题目链接:https://vjudge.net/contest/156903#problem/B

题意:

有一个递推公式 :

a,b都不是已知的,给出了 x1,x3,x5....

求x2,x4,x6....

枚举所有的 a,b,根据递推公式模运算即可;

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 int x[205];
 6 int t;
 7 const int mod = 10001;
 8 
 9 void solve()
10 {
11     for(int a=0; a<=10000; a++)
12     {
13         for(int b=0; b<=10000; b++)
14         {
15             bool ok = true;
16             for(int i=2; i<=2*t; i+=2)
17             {
18                 x[i] = (a*x[i-1] + b)%mod;
19                 if(i!=2*t&&x[i+1]!=(a*x[i]+b)%mod)
20                 {
21                     ok = false;
22                     break;
23                 }
24             }
25             if(ok) return;
26         }
27     }
28 }
29 
30 int main()
31 {
32 
33     while(scanf("%d",&t)!=EOF)
34     {
35         for(int i=1; i<=2*t-1; i+=2)
36         {
37             scanf("%d",&x[i]);
38         }
39 
40         solve();
41         for(int i=2; i<=2*t; i+=2)
42             printf("%d\n",x[i]);
43     }
44 
45     return 0;
46 }
View Code

 

转载于:https://www.cnblogs.com/TreeDream/p/6659333.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值