【NWERC2008】uva12169 Disgruntled Judge

229 篇文章 0 订阅
137 篇文章 0 订阅

Once upon a time, there was an NWERC judge with a tendency to create
slightly too hard problems. As a result, his problems were never
solved. As you can image, this made our judge somewhat frustrated.
This year, this frustration has culminated, and he has decided that
rather than spending a lot of time constructing a well-crafted
problem, he will simply write some insanely hard problem statement and
just generate some random input and output les. After all, why bother
having proper test data if nobody is going to try the problem anyway?
Thus, the judge generates a testcase by simply letting the input be a
random number, and letting the output be another random number.
Formally, to generate the data set with T test cases, the judge
generates 2 T random numbers x 1 ; : : : ; x 2 T between 0 and 10 000,
and then writes T , followed by the sequence x 1 ; x 3 ; x 5 ; : : : ;
x 2 T

枚举a,然后O(n)时间判断是否可行,总复杂度O(n*MOD)。
判断的时候,联立
ax1+b=x2(mod 10001)
ax2+b=x3(mod 10001)
得(a+1)b+10001k=x3-a^2*x1
用扩展欧几里得算法解出b,然后验证即可。

#include<cstdio>
#include<cstring>
const int mod=10001;
int f[110],g[110],n;
void euc(int a,int b,int &d,int &x,int &y)
{
    if (b==0)
    {
        d=a;
        x=1;
        y=0;
        return;
    }
    euc(b,a%b,d,y,x);
    y-=x*(a/b);
}
int main()
{
    int i,j,k,m,p,q,x,y,z,x1,x2,x3,a,b,d;
    bool flag;
    scanf("%d",&n);
    for (i=1;i<=n;i++)
      scanf("%d",&f[i]);
    for (a=0;a<mod;a++)
    {
        euc(a+1,mod,d,p,q);
        if ((f[2]-(long long)a*a*f[1])%d) continue;
        b=(p*(f[2]-(long long)a*a*f[1])/d)%mod;
        flag=1;
        g[1]=(f[1]*a+b)%mod;
        for (i=2;i<=n;i++)
        {
            if (f[i]!=(g[i-1]*a+b)%mod)
            {
                flag=0;
                break;
            }
            g[i]=(f[i]*a+b)%mod;
        }
        if (flag)
        {
            for (i=1;i<=n;i++)
              printf("%d\n",g[i]);
            return 0;
        }
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值