• Number Sequence


    http://poj.org/problem?id=1019

    题意:按照11212312341234561234567.。。123.。。。

        题意很简单,但是需要处理当数字大于9时,每一位仅算一个数字;

        使用数组a存每一组中有的个数,再用数组s存前i组的总个数;a[ i ] = a[ i - 1 ] + log10( i ) + 1 ;  其中log10( i )就是当数值大于9时所多出来的位数,例如12,就代表1、2;

        然后处理时,直接找到输入的n位于第i组,然后找出n位于该组中的位置,最后使用(i -  1 ) / 10 ^ ( 多出来的位数) % 10 ;因为每一个位置,都是0~9

    #include<map>
    #include<set>
    #include<list>
    #include<cmath>
    #include<ctime>
    #include<deque>
    #include<stack>
    #include<bitset>
    #include<cstdio>
    #include<vector>
    #include<cstdlib>
    #include<cstring>
    #include<iomanip>
    #include<numeric>
    #include<sstream>
    #include<utility>
    #include<iostream>
    #include<algorithm>
    #include<functional>
    
    using namespace std ;
    const int maxn = 31270 ;
    
    unsigned int a[ maxn ] , s[ maxn ] ;
    void Union()
    {
    	a[ 1 ] = 1 ;
    	s[ 1 ] = 1 ;
    	for( int i = 2 ; i < maxn ; ++i )
    	{
    		a[ i ] = a[ i - 1 ] + ( int )log10( ( double ) i ) + 1 ;
    		s[ i ] = s[ i - 1 ] + a[ i ] ;
    	}
    }
    
    int work( int n )
    {
    	int len = 0 , temp , pos , i = 1 ;
    	while( s[ i ] < n )	
    		++i ;
    	pos = n - s[ i - 1 ] ;
    	for( i = 1 ; len < pos ; ++i )
    		len += ( int )log10( ( double ) i ) + 1 ;
    	return ( ( i - 1 ) / ( int ) pow( ( double )10 , len - pos ) ) % 10 ;
    }
    
    int main()
    {
    	int Case , n ;
    	Union() ;
    	cin >> Case ;
    	while( Case-- )
    	{
    		cin >> n ;
    		cout << work( n ) << endl ;
    	}
        return 0;
    }
    


  • 相关阅读:
    Python OpenCV 常用操作
    Conda Cheatsheet | 速查表
    Loadrunner解决启动浏览器后页面显示空白
    26个ASP.NET常用性能优化方法
    C# Foreach用法
    体验ASP.NET MVC3 表单令牌功能!
    基于.Net(C#开发)平台的三层框架架构软件的设计与实现
    去掉浏览器中a标签的虚线
    Microsoft Dynamics CRM 4.0 序列号
    编写 Cookie
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3301534.html
Copyright © 2020-2023  润新知