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

为什么TLE啊 搞不懂

Posted by a350147909 at 2008-10-23 12:43:32 on Problem 1002
import java.io.*;
import java.util.*;


public class Test1002 {
	
	private static BufferedReader  stdIn =
		new  BufferedReader(new  InputStreamReader(System.in));
	private static PrintWriter  stdOut =
		new  PrintWriter(System.out, true);
	
	private static final int TEL_LENGTH = 7;
	
	public static void main(String[] args)throws Exception{
		int numberOfTel = 0;
		numberOfTel = Integer.parseInt(stdIn.readLine());
		String telNumber[] = new String[numberOfTel];
		StringTokenizer telNumberTokenizer[] = new StringTokenizer[numberOfTel];
		char telNumberArray[][] = new char[numberOfTel][TEL_LENGTH];
		int sameTelNumberArray[] = new int[numberOfTel];
		boolean yesOrNo = false;
		
		for(int i=0;i<sameTelNumberArray.length;i++){
			sameTelNumberArray[i] = 1;
		}
		
		for(int i=0;i<telNumber.length;i++){
			telNumber[i] = stdIn.readLine();
			
			telNumberTokenizer[i] = new StringTokenizer(telNumber[i],"-"); 
		}
		
		for(int i =0;i<telNumberTokenizer.length;i++){
			String telNumberC = "";
			while(telNumberTokenizer[i].hasMoreTokens()){
				telNumberC += telNumberTokenizer[i].nextToken();
			}
			telNumber[i] = telNumberC;
		}
		
		for(int i=0;i<telNumberArray.length;i++){
			telNumberArray[i] = telNumber[i].toCharArray();
		}
		
		//改字母为数字
		for(int i=0;i<telNumberArray.length;i++){
			for(int j=0;j<telNumberArray[i].length;j++)
				switch(telNumberArray[i][j]){
				

					
				case 'A':
				case 'B':
				case 'C':
					telNumberArray[i][j] = '2';
					break;
				case 'D':
				case 'E':
				case 'F':
					telNumberArray[i][j] = '3';
					break;
				case 'G':
				case 'H':
				case 'I':
					telNumberArray[i][j] = '4';
					break;
				case 'J':
				case 'K':
				case 'L':
					telNumberArray[i][j] = '5';
					break;
				case 'M':
				case 'N':
				case 'O':
					telNumberArray[i][j] = '6';
					break;
				case 'P':
				case 'R':
				case 'S':
					telNumberArray[i][j] = '7';
					break;
				case 'T':
				case 'U':
				case 'V':
					telNumberArray[i][j] = '8';
					break;
				case 'W':
				case 'X':
				case 'Y':
					telNumberArray[i][j] = '9';
					break;
					
					default:break;
				}
		}
		//将号码改为新格式
		for(int i=0;i<numberOfTel;i++){
			telNumber[i] = new String(telNumberArray[i]);
		}
		
		
		//for(int i=0;i<telNumber.length;i++)System.out.println(telNumber[i]);
		
		//排序 从小到大
		/*for(int i=0;i<numberOfTel;i++){
			for(int j=0;j<numberOfTel-i-1;j++)
				if(Integer.parseInt(telNumber[j])>Integer.parseInt(telNumber[j+1])){
					String s = telNumber[j+1];
					telNumber[j+1] = telNumber[j];
					telNumber[j] = s;
				}
			
			
		}*/
		
		quickSort(telNumber, 0, numberOfTel-1);
		
		//for(int i=0;i<telNumber.length;i++)System.out.println(telNumber[i]);
		
		//计算相同号码个数
		for(int i=0;i<telNumber.length-1;i++){
			
			//System.out.println(telNumber[i]);
			
			for(int j=i+1;j<telNumber.length;j++){
				
				if( telNumber[i]!=null && telNumber[i].equals(telNumber[j]) ){
					telNumber[j] = null;
					sameTelNumberArray[i]++;
				}
				
			}
		}
		
		for(int i=0;i<telNumber.length;i++){
			
			if(telNumber[i]!=null){
			telNumberArray[i] = telNumber[i].toCharArray();
			}
			
			
		}
		
		for(int i=0;i<sameTelNumberArray.length;i++){
			
			if(sameTelNumberArray[i]>1)
				yesOrNo = true;
				break;
		}
		
		
		
		if(yesOrNo){
			
		for(int i=0;i<telNumber.length;i++){
			
			
			if(telNumber[i]!=null && sameTelNumberArray[i]!=1){
				
			
			for(int j=0;j<TEL_LENGTH;j++){
				
				if(telNumber[i]!=null && j<3 )
					stdOut.print(telNumberArray[i][j]);
				else if(telNumber[i]!=null && j==3)
					stdOut.print("-"+telNumberArray[i][j]);
				else if(telNumber[i]!=null && j>3 )
					stdOut.print(telNumberArray[i][j]);
			}
			
			stdOut.println(" "+sameTelNumberArray[i]);
		}

	}
		}
		else
			stdOut.println("No duplicates.");
		

		
		
		
		
		
	}
	
	public static void quickSort(String [] a, int low, int high){
		
		int lo = low;
		int hi = high;
		
		//String key = a[low];
		
		if(lo>hi)
			return;
		
		boolean transfer=true; 

		while (lo != hi) { 
		if (Integer.parseInt(a[lo]) >Integer.parseInt(a[hi])) {
//		交换数字 
		String temp = a[lo]; 
		a[lo] = a[hi]; 
		a[hi] = temp; 
//		决定下标移动,还是上标移动 
		transfer = (transfer == true) ? false : true; 
		} 

//		将指针向前或者向后移动 
		if(transfer) 
		hi--; 
		else 
		lo++; 

//		显示每一次指针移动的数组数字的变化 
		/*for(int i = 0; i < a.length; ++i) { 
		System.out.print(a[i] + ","); 
		} 
		System.out.print(" (lo,hi) = " + "(" + lo + "," + hi + ")"); 
		System.out.println("");*/ 
		} 

//		将数组分开两半,确定每个数字的正确位置 
		lo--; 
		hi++; 
		quickSort(a, low, lo); 
		quickSort(a, hi, high); 
		} 
		
		
		
		
		
		
	}


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