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 Fudapeng at 2005-07-31 15:43:19 on Problem 2514
In Reply To:Re:WA WA WA ......WHY..........55555 Posted by:ync at 2005-07-31 15:13:02
#include "iostream.h"
#include "math.h"
#include "fstream.h"
long int nn,i;
__int64 second[100],bs[100],first[100],bf[100],k;

__int64 check(__int64 k,long int o)
{
	long int l=0;
	__int64 w[100];
	while (k>0)
	{w[++l]=k%10; k/=10;}
	o=l-o+1;
	return w[o];
}

__int64 change (__int64 k,long int o)
{
	__int64 kk=k; kk=kk*kk;
	long int l=0;
	__int64 w[100];
	while(kk>0)
	{w[++l]=kk%10; kk/=10;}
	o=l-o+1;
	return w[o];
}

int count(__int64 n,__int64& k1,__int64& k2)
{
	long int i; __int64 m;
	m=n;
	for (i=1;i<=9;i++)
		if (m>first[i]) m-=first[i];
		else 
		{
			if (m%i==0) 
			{k1=m/i+bf[i]-1; k1=check(k1,i);}
			else 
			{k1=m/i+bf[i]; m%=i; k1=check(k1,m);}
			m=0; break;
		}

	m=n;
	for (i=1;i<=18;i++)
		if (m>second[i]) m-=second[i];
		else 
		{
			if (m%i==0) 
			{k2=m/i+bs[i]-1; k2=change(k2,i);}
			else 
			{k2=m/i+bs[i]; m%=i; k2=change(k2,m);}
			m=0; break;
		}
	return 0;
}

int main()
{
	bf[1]=1; first[1]=9; k=9; 
	for (i=2;i<=9;i++)
	{bf[i]=bf[i-1]*10; k*=10; first[i]=k*i;}
	bf[10]=bf[9]*10;

	bs[1]=1; second[1]=3; k=3; __int64 o=10;
	for (i=2;i<=18;i++)
	{bs[i]=k+1; o*=10; k=sqrt(o-1); second[i]=i*(k-bs[i]+1);}
	bs[19]=k+1;

	while(true)
//	for (nn=1;nn<=985000;nn++)
	{
		cin>>nn;
		if (nn==0) return 0;
		__int64 n=nn;
		__int64 k1,k2,kk1,kk2;
		long int ans;

		count(n,k1,k2); count(n+1,kk1,kk2);
		if (kk1+kk2>9) ans=(k1+k2+1)%10;
		else 
		{
			if (kk1+kk2==9) 
			{
				n++; 
				do
				{n++; count(n,kk1,kk2);} 
				while(kk1+kk2==9);
				if (kk1+kk2>9) ans=(k1+k2+1)%10;
				else ans=(k1+k2)%10;
			} 
			else ans=(k1+k2)%10;
		}

		output<<ans<<endl;
	}

	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