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

Help me please... Runtime Error

Posted by Steinersp at 2006-12-05 13:20:27 on Problem 2606
Hi, I tried to do this problem, but I always got Runtime Error. I don't know why, because I think my code is correct... Please help me...

Here is my code:

import java.io.*;
import java.util.*;

class Main {
	
	static long x[];
	static long y[];
	public static int count(long mx, long my, int index) {
		
		int cont = 0;
		for (int i = 0; i < x.length; i ++)
			if (my * (x[index] - x[i]) == mx * (y[index] - y[i]))
				cont ++;
		
		return cont;
	}
	
	public static void main(String args[]) throws IOException {
		
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer token;
		
		int casos = Integer.parseInt(in.readLine());
		x = new long[casos];
		y = new long[casos];
		
		for (int i = 0; i < casos; i ++) {
			
			token = new StringTokenizer(in.readLine());
			x[i] = Long.parseLong(token.nextToken());
			y[i] = Long.parseLong(token.nextToken());
		}
		
		int max = 1;
		for (int i = 0; i < casos - 1; i ++) {
			
			for (int j = i + 1; j < casos; j ++) {
				
				long mx = x[i] - x[j];
				long my = y[i] - y[j];
				
				int tmp = count(mx, my, i);
				if (tmp > max)
					max = tmp;
			}
		}
		System.out.println(max);
	}
}

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