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

Java WA? please help

Posted by javaWarrior at 2007-01-17 00:33:59 on Problem 3150
why WA?

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

class Main{
	
static void cargarDistancias(long distancias[],int d,int order[],int orderInv[],int n,long cellular[]){
	
long min;
	
for(int i=0;i<n;i++)

 for(int j=0;j<n;j++){
 	
 min=Math.min(Math.abs(order[i]-orderInv[j]),n-Math.abs(order[i]-orderInv[j]));	
 distancias[i]+=(min<=d && order[i]!=orderInv[j])?cellular[orderInv[j]-1]:0;	
  	
 }	
	
}	

public static void main(String args[])throws IOException{
	
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//BufferedReader br = new BufferedReader(new FileReader("in.txt"));
StringBuffer s=new StringBuffer ();	
StringBuffer secuence;
StringTokenizer st;
String linea;
int n,m,d,k,i,j,y;
int []orderInv,order;
long []distancias,cellular;
ArrayList<String>x;
boolean flag;

//try{

while((linea=br.readLine())!=null)
{
	
st=new StringTokenizer(linea);

n=new Integer(st.nextToken());
m=new Integer(st.nextToken());
d=new Integer(st.nextToken());	
k=new Integer(st.nextToken());	

cellular=new long[n];
order=new int[n];
orderInv=new int[n];
x=new ArrayList<String>();
flag=false;

st=new StringTokenizer(br.readLine());

for(i=0;i<n;i++)
cellular[i]=new Long(st.nextToken());

for(i=0;i<n;i++){
order[i]=i+1;	
orderInv[i]=n-i;
}

inicio:
for(j=0;j<k;j++){
distancias=new long[n];
secuence=new StringBuffer();
cargarDistancias(distancias,d,order,orderInv,n,cellular);
for(i=0;i<n;i++){
secuence.append((cellular[i]+distancias[i])%m+" ");	
cellular[i]=(cellular[i]+distancias[i])%m;		
}
 
if(!x.contains(secuence.toString()))
x.add(secuence.toString());	
else
{
flag=true;	
break inicio;	
}
}

if(flag){
 
 y=x.size();
 i=0;
  
 while(true)
 {
 	
 if(j==k-1)break;	
 else{
 i++;	
 j++;	
 if(i==y)i=0;
 }
 }
 
 s.append(x.get(i));
  
 }
 else 
for(i=0;i<n;i++)
s.append(cellular[i]+" ");

s.append("\n");	
	
	
}
//}catch(IOException e){}
System.out.println(s);
}
}		

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