Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我的思路,,,0MS,,,希望抛砖能引玉,,,

Posted by 2011014326 at 2012-10-05 20:14:31 on Problem 1019
/*我的思路:
1.将长串数分成一个个部分,每个部分是从1到x的无重复的数字序列
2.每个序列比前一个序列多的位数是他的最后一个数的位数,如12345678910比123456789多最后一个10,
  即多占了两位,由此可推算出任何一个序列的长度
3.输入位置n,则从1到n查找,每次位置移动一个序列的长度,如果第j个加上序列长度超过n,则输出j这个整数的从个位数第j-n+1位上的数字
*/


#include<iostream>

#define A0 j/10==0
#define A1 j/10!=0
#define B0 j/100==0
#define B1 j/100!=0
#define C0 j/1000==0
#define C1 j/1000!=0
#define D0 j/10000==0
#define D1 j/10000!=0
#define E0 j/100000==0
#define E1 j/100000!=0

using namespace std;
int main()
{
	unsigned int data[100000]={0};
	int record[6]={0};
	unsigned int n,num,i,i1,j,k,m,a,a1,b;
	cin>>n;
	while(n--)
	{
		cin>>num;
		data[0]=0;
		i=i1=0;
		for(j=1;;j++)
		{
			if(A0) k=1;
			if(A1&&B0) k=2;
			if(B1&&C0) k=3;
			if(C1&&D0) k=4;
			if(D1&&E0) k=5;
			if(E1) k=6;
			data[j]=data[j-1]+k;
			m=1;
			if(i+data[j]<num)
                i+=data[j];
			else
			{
				m=num-i;
				for(a=1;a<=j;a++)
				{
					if(data[a]>=m)
						break;
				}
				a1=a;
				for(b=0;b<6;b++)
				{
					if(a1)
					{
						record[b]=a1%10;
						a1/=10;
					}
				}
				
				cout<<record[data[a]-m]<<endl;

				break;
			}
		}
	}

	return 0;
}




Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator