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

Re:终于用java过了这个bt题~~

Posted by zymx at 2005-09-15 18:49:19 on Problem 2602
In Reply To:终于用java过了这个bt题~~ Posted by:zymx at 2005-09-10 10:33:20
用Java解这题,必须解决的是I/O瓶颈,和C/C++相似,如果我们用了
Scanner/Token,那几乎一定会导致超时。

采用Stream类的read(byte[])和write(byte[])方法,可以将时间缩短到
时限之内,加上BufferedStream wrapper后,时间可能再缩短到三分之一。

这是我的代码:
	void solve()throws Exception{
		BufferedInputStream in=new BufferedInputStream(System.in);				
		sz=in.read(a);
		int N=nextInt();
		byte c[]=new byte[N];
		for(int i=0;i<N;i++)
			c[i]=(byte)(nextDigit()+nextDigit());
		int cf=0;
		for(int i=N-1;i>=0;i--){
			c[i]+=cf;
			if (c[i]>=10) {cf=1;c[i]+=38;} else {cf=0;c[i]+=48;};
		}
		System.out.write(c);
		System.out.println();
	}
其中nextInt()和nextDigit()是自己写的parse函数,a是足够大的byte array.

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