| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Input data seems short!I get AC on this problem, and I think the input data is short.
My program get AC when I write
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
int m = sc.nextInt();
double[] xs = new double[n];
double[] ys = new double[n];
for(int i=0;i<n;i++){
xs[i] = sc.nextDouble();
ys[i] = sc.nextDouble();
}
double[][] wmat = new double[n][n];
for(double[] line:wmat) Arrays.fill(line, INF);
try{
for(int i=0;i<m;i++){
int v1 = sc.nextInt() - 1;
int v2 = sc.nextInt() - 1;
double dx = xs[v1] - xs[v2];
double dy = ys[v1] - ys[v2];
wmat[v1][v2] = Math.sqrt(dx*dx+dy*dy);
}
}catch(NoSuchElementException e){
// while(true);
}
Main main = new Main(n, wmat);
main.solve();
}
}
but get TLE
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
int m = sc.nextInt();
double[] xs = new double[n];
double[] ys = new double[n];
for(int i=0;i<n;i++){
xs[i] = sc.nextDouble();
ys[i] = sc.nextDouble();
}
double[][] wmat = new double[n][n];
for(double[] line:wmat) Arrays.fill(line, INF);
try{
for(int i=0;i<m;i++){
int v1 = sc.nextInt() - 1;
int v2 = sc.nextInt() - 1;
double dx = xs[v1] - xs[v2];
double dy = ys[v1] - ys[v2];
wmat[v1][v2] = Math.sqrt(dx*dx+dy*dy);
}
}catch(NoSuchElementException e){
while(true);
}
Main main = new Main(n, wmat);
main.solve();
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator