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

搞清楚了,对输入排序以后输出应该恢复原顺序这个事情我给忘了……自问自答,我有罪……

Posted by Gerhut at 2006-09-14 21:13:49 on Problem 1019
In Reply To:搞不清楚我这段代码哪里会WA,请教 Posted by:Gerhut at 2006-09-14 20:59:37
> #include <cstdio>
> #include <cstring>
> using namespace std;
> 
> int log10(int n)
> {
> 	if(n<10)return 0;
> 	if(n<100)return 1;
> 	if(n<1000)return 2;
> 	if(n<10000)return 3;
> 	return 4;
> }
> int pow10(int n)
> {
> 	if(n==0)return 1;
> 	if(n==1)return 10;
> 	if(n==2)return 100;
> 	if(n==3)return 1000;
> 	if(n==4)return 10000;
> }
> 
> long width(int n)
> {
> 	long r=0;
> 	for(int i=1;i<=log10(n);i++)
> 	{
>                 r+=9*long(pow10(i-1))*i;
> 	}
> 	r+=(n-pow10(log10(n))+1)*(log10(n)+1);
> 	return r;
> }
> 
> int main()
> {
> 	int n;
> 	scanf("%d",&n);
> 	long m[n];
> 	for(int i=0;i<n;i++)
> 	{
> 		scanf("%d",&m[i]);
> 		for(int j=i-1;m[j+1]<m[j]&&j>=0;j--)
> 		{
> 			long t=m[j+1];
> 			m[j+1]=m[j];
> 			m[j]=t;
> 		}
> 	}
> 	unsigned long k=0;
> 	int p=0;
> 	for(int j=1;;j++)
> 	{
> 		long w=width(j);
> 		long w2=w;
> 		while(k+w2>=m[p])
> 		{
> 			w=w2;
> 			for(int i=j;i>0;i--)
> 			{
> 				char a[20];
> 				sprintf(a,"%d",i);
> 				w-=strlen(a);
> 				if(k+w<m[p])
> 				{
> 					printf("%c\n",a[m[p]-k-w-1]);
> 					break;
> 				}
> 			}
> 			p++;
> 			if(p==n)goto ending;
> 		}
> 		k+=w2;
> 	}
> 	ending:
> 	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