• BZOJ2296: 【POJ Challenge】随机种子


    2296: 【POJ Challenge】随机种子

    Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special Judge
    Submit: 114  Solved: 54
    [Submit][Status]

    Description

    1tthinking除了随机算法,其他什么都不会。但是他还是可以ac很多题目,他用的是什么呢?他会选择一个好的随机种子,然后输出答案。往往他选择的一个好的种子可以有99%的概率ac题目。

    他会按照下面的规则选择一个种子。首先1tthinking有自己喜欢的一个幸运数字 x。然后他会找一个数字 a 使得 (1)a is a 是 x 的倍数 (2) a 的十进制表示包含0到9。

    举个例子, 如果 x = 1, 那么 9182736450 就是一个1tthinking需要的随机种子。

    然而1tthinking有的时候花了很久也找不到这个数,他感到很失望。现在他把问题留给了你。

    Input

     

    第1行,一个整数 T (0 ≤ T ≤ 100), 幸运数字的数量。

    第2到 T + 1行: Xi (0 ≤ Xi ≤ 106), 1tthinking的幸运数字。

    Output

     

    第1到 T: 一个整数 Yi (0 ≤ Yi ≤ 1016), 满足条件的随机种子. 如果不存在,输出-1。

    Sample Input

    3
    1
    2
    10

    Sample Output

    9876543210
    9876543210
    9876543210

    HINT

    Source

    题解:
    500T做了这么一道逗逼题。。。
    10+6=16。。。
    所以我们从1234567890-000000开始枚举,到达1234567890-999999一定有被x整除的数,因为x<=100W
    注意0输出-1
    代码:
     1 #include<cstdio>
     2 
     3 #include<cstdlib>
     4 
     5 #include<cmath>
     6 
     7 #include<cstring>
     8 
     9 #include<algorithm>
    10 
    11 #include<iostream>
    12 
    13 #include<vector>
    14 
    15 #include<map>
    16 
    17 #include<set>
    18 
    19 #include<queue>
    20 
    21 #include<string>
    22 
    23 #define inf 1000000000
    24 
    25 #define maxn 100000
    26 
    27 #define maxm 500+100
    28 
    29 #define eps 1e-10
    30 
    31 #define ll long long
    32 
    33 #define pa pair<int,int>
    34 
    35 #define for0(i,n) for(int i=0;i<=(n);i++)
    36 
    37 #define for1(i,n) for(int i=1;i<=(n);i++)
    38 
    39 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
    40 
    41 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
    42 
    43 #define mod 1000000007
    44 
    45 using namespace std;
    46 
    47 inline int read()
    48 
    49 {
    50 
    51     int x=0,f=1;char ch=getchar();
    52 
    53     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    54 
    55     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
    56 
    57     return x*f;
    58 
    59 }
    60 
    61 int main()
    62 
    63 {
    64 
    65     freopen("input.txt","r",stdin);
    66 
    67     freopen("output.txt","w",stdout);
    68 
    69     int n=read();
    70     while(n--)
    71     {
    72         ll x=read();ll i;
    73         if(!x){printf("%d
    ",-1);continue;}
    74         for(i=1234567890000000ll;i%x;i++);
    75         printf("%lld
    ",i);
    76     }
    77 
    78     return 0;
    79 
    80 } 
    View Code
  • 相关阅读:
    一文了解快排的各种形式和坑
    逆序对的数量
    __type_traits 技法
    Traits 编程技法
    一个简单的内存管理器
    「ZooKeeper」概述
    「MySQL」explain
    「MySQL」InnoDB加锁情况
    「MySQL45讲」个人总结
    「MySQL45讲」1-45讲
  • 原文地址:https://www.cnblogs.com/zyfzyf/p/4110575.html
Copyright © 2020-2023  润新知