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

纯数据操作,不做表格O(logn)时间

Posted by freshvictor at 2010-07-01 14:34:52 on Problem 1019 and last updated at 2010-07-01 14:36:26
小弟的思路:
1.逐次减去区间长度,得到最后区间1.....m的长度
2.逐次减去能减去的最大区间如1....m-1的长度
得到最终的若干位,通过字符输出 16MS

#include <iostream>
#include <stdlib.h>
#include <cmath>
using namespace std;

int main()
{
	char rst[20];
	int length[100000], t, test, maxi;
	cin >> t;
	memset(length, 0, sizeof(length));
	while (t--)
	{
		cin >> test;
		int temp, rsti, tempi;
		maxi = 1; temp = test;
		while (temp > length[maxi-1])
		{
			temp -= length[maxi-1];
			length[maxi] = length[maxi-1] + (int)log10((double)maxi) + 1;
			maxi++;
		}	
		rsti = 0; tempi = 1; 
		while (1)
		{
			rsti += (int)log10((double)tempi) + 1;
			if (rsti == temp) {rsti = (int)log10((double)tempi);break;}
			else if (rsti > temp) {rsti -= temp; rsti = ((int)log10((double)tempi))- rsti; break;}
			tempi++;
		}
		_itoa_s(tempi, rst, 10);
		cout << rst[rsti] << 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