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

OMS迅速水过...

Posted by aa2985759 at 2010-12-04 00:19:55 on Problem 1019
#include<iostream>
#include<vector>
using namespace std;
int main()
{
	unsigned long a[50000],sum[50000];
	int i,n,j,m;
	vector<int>v;
	a[0]=sum[0]=0;
	j=1;
	for(i=1;i<50000;i++)
	{
		a[i]=a[i-1]+j;
		sum[i]=a[i]+sum[i-1];
		if(i==9||i==99||i==999||i==9999)
			j++;
	}
	cin>>n;
	while(n--)
	{
		scanf("%d",&m);
		i=0;
		v.clear();
		if(m>sum[999])
		{
			if(m>sum[19999])
				i=9999;
			else i=999;
		}
		while(m>sum[i])
			i++;
		m-=sum[i-1];
		i=0;
		while(m>a[i])
			i++;
		m-=a[i-1];
		while(i)
			v.push_back(i%10),i/=10;
		printf("%d\n",*(v.end()-m));
	}
}

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