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 2004huangyimin at 2007-07-28 01:38:43 on Problem 1019
#include <iostream>
#include <math.h>
using namespace std;
long  double func(long double A,long double B,long double C)
{
	long double result;
	result = (((-1)*B)+sqrt(B*B-4*A*C)) / (2*A);
	//cout <<"sqrt = "<< result <<endl;
	return result;
}
long double Location(long double n)
{
	long double temp = (long double)n;

	if ( n <= 45 && n >= 1)
	{
		return func(1.0,1.0,-2*temp);
	} 
	else if (n > 45 && n <= 9045 )
	{
		return func(1.0,-8.0,36.0-temp);
	} 
	else if (n > 9045 && n<= 1395495)
	{
		return func(1.0,-71.0,(-1.0)*(temp-9045.0)*2.0/3.0-2772.0);
	}
	else if (n > 1395495 && n <= 189414495)
	{
		return func(2.0,-1105.0,-892107.0+1395495.0-temp);
	} 
	else if ( n > 189414495 && n <= 23939649495)
	{
		return func(5.0,-22207.0,(-2.0)*(temp-189414495.0)-277852212.0);
	}
	else
	{
		//cout << "fail!"<<endl;
		return -1.0;
	}
}

unsigned int CoLocation(unsigned int input)
{
	if (input >= 1&&input <= 9)
	{
		return (input*input+input) / 2;
	}
	else if (input >= 10 && input <= 99)
	{
		return (input*input-8*input+36);
	} 
	else if (input >= 100&&input <= 999)
	{
		return (9045 + (3 * input + 84)*(input - 99) / 2);
	}
	else if (input >= 1000&& input <= 9999)
	{
		return (1395495+2*input*input - 1105*input - 892107);;
	} 
	else if (input >= 10000&& input <= 99999)
	{
		return (189414495 + (5*input*input-22207*input - 277852212) / 2);
	}
	else
	{
		//cout << "fail"<<endl;
		return -5;
	}
}

unsigned long int PosToRang(unsigned long int off,unsigned int long bs)
{
	if (off % bs != 0)
	{
		return (off / bs) + 1;
	}
	else
	{
		return off / bs;
	}
}

unsigned long int MyPow(unsigned long int y)
{
	unsigned long int i;
	unsigned long int p = 1;
	for ( i = 0;i < y;++i)
	{
		p *= 10;
	}
	return p;
}

unsigned long int HandleForDig(unsigned long int off,unsigned long int bs,unsigned long int area)
{
	unsigned long int t;
	t = off % bs; 
	if( t == 0)
	{
		return area % 10;
	}
	else
	{
		return (area / MyPow(bs-1));
	}

}

unsigned long int PosToDigit(unsigned long int offset,unsigned long int area)
{
	if ( offset == 0)
	{
		return (area%10);
	}
	else if (offset > 0)
	{
		if (offset >= 1&&offset <= 9)
		{
			return offset;
		}
		if (offset >= 10&& offset <= 189)
		{
			unsigned long int f = offset - 9;
			unsigned long int tmp;
			tmp = PosToRang(f,2) + 9;
			return HandleForDig(f,2,tmp);
		}
		if (offset >= 190 && offset <= 2889)
		{
			unsigned long int tmp;
			unsigned long int f = offset - 189;
			tmp = PosToRang(f,3) + 99;
			return HandleForDig(f,3,tmp);
		}
		if (offset >= 2890 && offset <= 38889)
		{
			unsigned long int f = offset - 2889;
			unsigned long int tmp;
			tmp = PosToRang(f,4) + 999;
			return HandleForDig(f,4,tmp);
		}
		if (offset >= 38890 && offset <= 488889 )
		{
			unsigned long int f = offset - 38889;
			unsigned long int tmp;
			tmp = PosToRang(f,5)+9999;
			return HandleForDig(f,5,tmp);
		}
	}
	else
	{
		//cout << "fail!"<<endl;
		return -1;
	}
}

int main()
{
	long double input;
	unsigned long int tmp;
	unsigned long int num;
	cin >> num;
	while (num > 0)
	{
		cin >> input;
		tmp = (unsigned long int)(Location(input));
		//cout << "CoLoation = "<<CoLocation(tmp)<<endl;
		unsigned long int base = (unsigned long int)input - CoLocation(tmp);
		cout << PosToDigit(base,tmp)<<endl;
		--num;
	}
	return EXIT_SUCCESS;
}

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