zoukankan      html  css  js  c++  java
  • 【数学】【模拟】XMU 1044 伪伪随机数产生器

    题目链接:

      http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1044

    题目大意

      求首项为0,公比为x的等差数列组成的数字条的第y位数字是几。(x,y<=2*109)

    题目思路:

      【数学】【模拟】

      万万没想到这道题暴力我就过了。

      0ms是计算在x为公差的情况下每位数会有几个数列中的数(例如x=3,369121518...一位数就有3个)

      直接计算第y个数字是包含在几位数的等差数列中,是第几个数字。

    暴力:

     1 //
     2 //by coolxxx
     3 //
     4 #include<iostream>
     5 #include<algorithm>
     6 #include<string>
     7 #include<iomanip>
     8 #include<memory.h>
     9 #include<time.h>
    10 #include<stdio.h>
    11 #include<stdlib.h>
    12 #include<string.h>
    13 //#include<stdbool.h>
    14 #include<math.h>
    15 #define min(a,b) ((a)<(b)?(a):(b))
    16 #define max(a,b) ((a)>(b)?(a):(b))
    17 #define abs(a) ((a)>0?(a):(-(a)))
    18 #define lowbit(a) (a&(-a))
    19 #define sqr(a) ((a)*(a))
    20 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
    21 #define eps (1e-8)
    22 #define J 10000000
    23 #define MAX 0x7f7f7f7f
    24 #define PI 3.1415926535897
    25 #define N 104
    26 using namespace std;
    27 typedef long long LL;
    28 int cas,cass;
    29 int n,m,lll,ans;
    30 LL sum;
    31 LL e[N];
    32 int get(LL x)
    33 {
    34     int i=1;
    35     while(x>=e[i+1])i++;
    36     return i;
    37 }
    38 int main()
    39 {
    40     #ifndef ONLINE_JUDGE
    41 //    freopen("1.txt","r",stdin);
    42 //    freopen("2.txt","w",stdout);
    43     #endif
    44     int i,j;
    45 //    for(scanf("%d",&cas);cas;cas--)
    46 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
    47 //    while(~scanf("%s",s))
    48     e[0]=0,e[1]=1;
    49     for(i=2;i<=19;i++)e[i]=e[i-1]*10;
    50     while(~scanf("%d",&n))
    51     {
    52         scanf("%d",&m);
    53         i=0;
    54         j=get(n);
    55         for(sum=n;i<m;sum+=n,i+=j)
    56         {
    57             if(sum>=e[j+1])j++;
    58         }
    59         sum-=n;
    60         if(i==m)printf("%d
    ",sum%10);
    61         else
    62         {
    63             i=m-(i-j);
    64             printf("%d
    ",sum/e[j-i+1]%10);
    65         }
    66     }
    67     return 0;
    68 }
    69 /*
    70 //
    71 
    72 //
    73 */
    千万不要点

     数学:

     1 //
     2 //by coolxxx
     3 //
     4 #include<iostream>
     5 #include<algorithm>
     6 #include<string>
     7 #include<iomanip>
     8 #include<memory.h>
     9 #include<time.h>
    10 #include<stdio.h>
    11 #include<stdlib.h>
    12 #include<string.h>
    13 //#include<stdbool.h>
    14 #include<math.h>
    15 #define min(a,b) ((a)<(b)?(a):(b))
    16 #define max(a,b) ((a)>(b)?(a):(b))
    17 #define abs(a) ((a)>0?(a):(-(a)))
    18 #define lowbit(a) (a&(-a))
    19 #define sqr(a) ((a)*(a))
    20 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
    21 #define eps (1e-8)
    22 #define J 10000000
    23 #define MAX 0x7f7f7f7f
    24 #define PI 3.1415926535897
    25 #define N 104
    26 using namespace std;
    27 typedef long long LL;
    28 LL cas,cass;
    29 LL n,m,lll,ans;
    30 LL s[24];
    31 LL x;
    32 int main()
    33 {
    34     #ifndef ONLINE_JUDGE
    35 //    freopen("1.txt","r",stdin);
    36 //    freopen("2.txt","w",stdout);
    37     #endif
    38     LL i,j;
    39 //    for(scanf("%d",&cas);cas;cas--)
    40 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
    41 //    while(~scanf("%s",s))
    42     while(~scanf("%lld",&n))
    43     {
    44         scanf("%lld",&m);
    45         if(n==0)
    46         {
    47             puts("0");
    48             continue;
    49         }
    50         for(i=1,x=10;i<19;i++,x*=10)
    51             s[i]=(x-1)/n;
    52         for(i=18;i>1;i--)
    53             s[i]-=s[i-1];
    54         for(i=1,x=0;i<19 && m>=s[i]*i;i++)
    55             m-=s[i]*i,x+=s[i]*n;
    56         x+=m/i*n;
    57         if(m%i==0)
    58         {
    59             printf("%d
    ",x%10);
    60             continue;
    61         }
    62         x+=n;
    63         i-=m%i;
    64         while(i--)x/=10;
    65         printf("%d
    ",x%10);
    66     }
    67     return 0;
    68 }
    69 /*
    70 //
    71 
    72 //
    73 */
    千万不要点
  • 相关阅读:
    从头认识java-2.6 逗号操作符
    JavaScript基础知识
    特性选择器
    文本缩进
    如何使图片与导航栏对齐
    如何使用CSS选择器应用于子元素
    图像
    布局
    列表,表格和表单
    盒子
  • 原文地址:https://www.cnblogs.com/Coolxxx/p/5669492.html
Copyright © 2011-2022 走看看