• hdu 2769 uva 12169 Disgruntled Judge 拓展欧几里德


    //数据是有多水 连 10^10的枚举都能过

    关于拓展欧几里德:大概就是x1=y2,y1=x2-[a/b]y2,按这个规律递归到gcd(a,0)的形式,此时公因数为a,方程也变为a*x+0*y=gcd(a,0)的形式,显然解为x=1,y=0,然后再递归回去就能得到解(a*x+b*y=gcd(a,b)的解)

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cmath>
     4 #include<algorithm>
     5 #include<cstring>
     6 #include<cstdlib>
     7 #include<queue>
     8 #include<vector>
     9 #include<map>
    10 #include<stack>
    11 #include<string>
    12 
    13 using namespace std;
    14 
    15 long long T;
    16 long long x[201];
    17 
    18 void exGED(long long a,long long b,long long &d,long long &x,long long &y){
    19     if (b==0){
    20             x=1;
    21             y=0;
    22             d=a;
    23     }
    24     else{
    25             exGED(b,a%b,d,x,y);
    26             long long tmp=x;
    27             x=y;
    28             y=tmp-(a/b)*y;
    29     }
    30 }
    31 
    32 bool solve(long long a){
    33     long long d,b,k;
    34     long long tmp=x[3]-a*a*x[1];
    35     exGED(a+1,10001,d,b,k);
    36     if (tmp%d!=0) return false;
    37     b=b*(tmp/d);
    38     for (long long i=2;i<=2*T;i++){
    39             if (i%2==0){
    40                     x[i]=(x[i-1]*a+b)%10001;
    41             }
    42             else{
    43                     if (x[i]!=((x[i-1]*a+b)%10001)){
    44                             return false;
    45                     }
    46             }
    47     }
    48     for (long long i=2;i<=2*T;i+=2){
    49             printf("%I64d
    ",x[i]);
    50     }
    51     return true;
    52 }
    53 
    54 int main(){
    55     scanf("%I64d",&T);
    56     for (long long i=1;i<2*T;i+=2){
    57             scanf("%I64d",&x[i]);
    58     }
    59     //solve(1096);
    60     for (long long a=0;a<=10000;a++){
    61             if (solve(a)) break;
    62     }
    63     return 0;
    64 }
    65 /*
    66 3
    67 17
    68 822
    69 3014
    70 */
    View Code
  • 相关阅读:
    wpf Behavior
    wpf Trigger
    语法糖
    Lambda 表达式
    wpf 3D动画
    IEnumerable接口学习
    Delegates, Events, and Anonymous Methods 委托、事件与匿名方法
    wpf 平滑效果随记
    软件工程第一篇博客
    记考研高数第一课
  • 原文地址:https://www.cnblogs.com/baby-mouse/p/4635271.html
Copyright © 2020-2023  润新知