zoukankan      html  css  js  c++  java
  • HDU 1597 find the nth digit

    数学题。


    弄懂了之久事实上就是解一个一元二次方程 x*(x-1)/2=y 。

    假设y==0了。表明刚好是这个数。

    不是的话,就x取大一位然后 y-n 再%9 。

    只是记得 %9==0的时候是9。

    不会出现0。




    <pre name="code" class="cpp">#include<cstdio>
    #include<cstring>
    #include<string>
    #include<queue>
    #include<algorithm>
    #include<map>
    #include<stack>
    #include<iostream>
    #include<list>
    #include<set>
    #include<cmath>
    #define INF 0x7fffffff
    #define eps 1e-6
    #define LL long long
    using namespace std;
    int main()
    {
    
    //    int a=0x3fffffff+1;
    //    cout<<a;
    //    1
    //    freopen("in.txt","r",stdin);
    //    freopen("2.txt","w",stdout);
        int t;
        scanf("%d",&t);
        while(t--)
        {
            double n,x;
            int y;
            scanf("%lf",&n);
            x = int((sqrt(1.0 + 8.0*n) -1)/2);
            y = int(n-x*(x+1)/2);
    
            if(y == 0)//刚好是 n*(n+1)/2
            {
                if(int(x)%9 == 0)
                    printf("9
    ");
                else
                    printf("%d
    ", int(x)%9);
            }
            else//在之间
            {
                if(y%9 == 0)
                    printf("9
    ");
                else
                    printf("%d
    ", y%9);
            }
        }
    }
    

    
    

  • 相关阅读:
    事务
    MySQL删除表的方式
    建立索引的原则
    对表设置引擎
    运算符
    数据库锁简介
    为什么对表设置主键
    php苹果原生apns推送接口
    华为推送
    php操作redis
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/7144336.html
Copyright © 2011-2022 走看看