zoukankan      html  css  js  c++  java
  • bzoj 3751[NOIP2014]解方程

    嘿嘿嘿,还是不怎么会做,太tmd神奇了

     1 #include<bits/stdc++.h>
     2 #define inf 0x7fffffff
     3 #define LL long long
     4 #define N 100005
     5 using namespace std;
     6 inline int ra()
     7 {
     8     int x=0,f=1; char ch=getchar();
     9     while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();}
    10     while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
    11     return x*f;
    12 }
    13 int mod[5]={11261,19997,22877,21893,14843};
    14 int n,m;int ans[1000005];
    15 int a[5][105],pre[5][105],res[5][30005];
    16 char ch[10005];
    17 int cal(int t, int x)
    18 {
    19     int sum=0;
    20     for (int i=0; i<=n; i++)
    21         sum=(sum+a[t][i]*pre[t][i])%mod[t];
    22     if (sum<0) sum+=mod[t];
    23     return sum;
    24 }
    25 bool judge(int x)
    26 {
    27     for (int t=0; t<5; t++)
    28         if (res[t][x%mod[t]]!=0) return 0;
    29     return 1;
    30 }
    31 int main()
    32 {
    33     n=ra(); m=ra();
    34     for (int i=0; i<=n; i++)
    35     {
    36         scanf("%s",ch+1);
    37         int l=strlen(ch+1);
    38         bool flag=0;
    39         for (int t=0; t<5; t++)
    40             if (ch[1]!='-') a[t][i]=ch[1]-'0';
    41             else a[t][i]=0,flag=1;
    42         for (int t=0; t<5; t++)
    43         {
    44             for (int k=2; k<=l; k++)
    45                 a[t][i]=(a[t][i]*10+ch[k]-'0')%mod[t];
    46             if (flag) a[t][i]=-a[t][i];
    47         }
    48     }
    49     for (int t=0; t<5; t++)
    50         for (int x=1; x<mod[t]; x++)
    51         {
    52             pre[t][0]=1;
    53             for (int i=1; i<=n; i++) pre[t][i]=(pre[t][i-1]*x)%mod[t];
    54             res[t][x]=cal(t,x);
    55         }
    56     for (int i=1; i<=m; i++)
    57         if (judge(i)) ans[++ans[0]]=i;
    58     printf("%d
    ",ans[0]);
    59     for (int i=1; i<=ans[0]; i++)
    60         printf("%d
    ",ans[i]);
    61     return 0;
    62 }
  • 相关阅读:
    第三周java学习总结
    第一周Java学习总结
    关闭窗体
    乱七八糟
    网页游戏资料
    timer控件的使用
    spread 签套循环改变颜色编号为颜色
    限制输入‘号的代码
    SQlcharindex命令
    限制输入类型
  • 原文地址:https://www.cnblogs.com/ccd2333/p/6385324.html
Copyright © 2011-2022 走看看