534 - Frogger
Moderator: Board moderators
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
534 - Frogger
Could anyone help me?
I use to solve this problem following algorith:
1. read data
2. build full graph - compute connections to all other stones from any.
3. use BFS to find minimal distance which is necessary to reach every stone from all other.
4. output result
What do I miss?
Could anyone send me some special cases?
Is there a problem with rouding errors ?
Best regards
Dominik
I use to solve this problem following algorith:
1. read data
2. build full graph - compute connections to all other stones from any.
3. use BFS to find minimal distance which is necessary to reach every stone from all other.
4. output result
What do I miss?
Could anyone send me some special cases?
Is there a problem with rouding errors ?
Best regards
Dominik
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
Can someone please either give me some cases or help check my code, because my solution got wa even though the implementation is correct
[c]
#include <stdio.h>
#include <string.h>
#include <math.h>
int n,i,j,count = 1;
long k,l;
int coord[200][2];
long matrix[200][200];
long min(long a,long b) {
if (a > b) return b;
else return a;
}
int main () {
while (1) {
scanf("%d",&n);
if (n == 0) return 0;
memset(matrix,0,sizeof(matrix));
for (i = 0;i < n;i++) scanf("%d %d",&coord[0],&coord[1]);
for (i = 0;i < n;i++) {
for (j = 0;j < n;j++) {
if (i != j) {
k = (long) (coord[0] - coord[j][0]);
l = (long) (coord[1] - coord[j][1]);
matrix[j] = k * k + l * l;
}
}
}
for (i = 0;i < n;i++) {
for (j = 0;j < n;j++) {
for (k = 0;k < n;k++) {
if ((i != j) && (j != k))
if (matrix[k] > min(matrix[j],matrix[j][k]))
matrix[k] = min(matrix[j],matrix[j][k]);
}
}
}
printf("Scenario #%d\n",count);
printf("Frog Distance = %.3lf\n\n",sqrt((double)matrix[0][1]));
count++;
}
}
[/c]
[c]
#include <stdio.h>
#include <string.h>
#include <math.h>
int n,i,j,count = 1;
long k,l;
int coord[200][2];
long matrix[200][200];
long min(long a,long b) {
if (a > b) return b;
else return a;
}
int main () {
while (1) {
scanf("%d",&n);
if (n == 0) return 0;
memset(matrix,0,sizeof(matrix));
for (i = 0;i < n;i++) scanf("%d %d",&coord[0],&coord[1]);
for (i = 0;i < n;i++) {
for (j = 0;j < n;j++) {
if (i != j) {
k = (long) (coord[0] - coord[j][0]);
l = (long) (coord[1] - coord[j][1]);
matrix[j] = k * k + l * l;
}
}
}
for (i = 0;i < n;i++) {
for (j = 0;j < n;j++) {
for (k = 0;k < n;k++) {
if ((i != j) && (j != k))
if (matrix[k] > min(matrix[j],matrix[j][k]))
matrix[k] = min(matrix[j],matrix[j][k]);
}
}
}
printf("Scenario #%d\n",count);
printf("Frog Distance = %.3lf\n\n",sqrt((double)matrix[0][1]));
count++;
}
}
[/c]
Can someone please either give me some cases or help check my code, because my solution got wa even though the implementation is correct
[c]
#include <stdio.h>
#include <string.h>
#include <math.h>
int n,i,j,count = 1;
long k,l;
int coord[200][2];
long matrix[200][200];
long min(long a,long b) {
if (a > b) return b;
else return a;
}
int main () {
while (1) {
scanf("%d",&n);
if (n == 0) return 0;
memset(matrix,0,sizeof(matrix));
for (i = 0;i < n;i++) scanf("%d %d",&coord[0],&coord[1]);
for (i = 0;i < n;i++) {
for (j = 0;j < n;j++) {
if (i != j) {
k = (long) (coord[0] - coord[j][0]);
l = (long) (coord[1] - coord[j][1]);
matrix[j] = k * k + l * l;
}
}
}
for (i = 0;i < n;i++) {
for (j = 0;j < n;j++) {
for (k = 0;k < n;k++) {
if ((i != j) && (j != k))
if (matrix[k] > min(matrix[j],matrix[j][k]))
matrix[k] = min(matrix[j],matrix[j][k]);
}
}
}
printf("Scenario #%d\n",count);
printf("Frog Distance = %.3lf\n\n",sqrt((double)matrix[0][1]));
count++;
}
}
[/c]
[c]
#include <stdio.h>
#include <string.h>
#include <math.h>
int n,i,j,count = 1;
long k,l;
int coord[200][2];
long matrix[200][200];
long min(long a,long b) {
if (a > b) return b;
else return a;
}
int main () {
while (1) {
scanf("%d",&n);
if (n == 0) return 0;
memset(matrix,0,sizeof(matrix));
for (i = 0;i < n;i++) scanf("%d %d",&coord[0],&coord[1]);
for (i = 0;i < n;i++) {
for (j = 0;j < n;j++) {
if (i != j) {
k = (long) (coord[0] - coord[j][0]);
l = (long) (coord[1] - coord[j][1]);
matrix[j] = k * k + l * l;
}
}
}
for (i = 0;i < n;i++) {
for (j = 0;j < n;j++) {
for (k = 0;k < n;k++) {
if ((i != j) && (j != k))
if (matrix[k] > min(matrix[j],matrix[j][k]))
matrix[k] = min(matrix[j],matrix[j][k]);
}
}
}
printf("Scenario #%d\n",count);
printf("Frog Distance = %.3lf\n\n",sqrt((double)matrix[0][1]));
count++;
}
}
[/c]
Can someone please either give me some cases or help check my code, because my solution got wa even though the implementation is correct
[c]
#include <stdio.h>
#include <string.h>
#include <math.h>
int n,i,j,count = 1;
long k,l;
int coord[200][2];
long matrix[200][200];
long max(long a,long b) {
if (a < b) return b;
else return a;
}
int main () {
while (1) {
scanf("%d",&n);
if (n == 0) return 0;
memset(matrix,0,sizeof(matrix));
for (i = 0;i < n;i++) scanf("%d %d",&coord[0],&coord[1]);
for (i = 0;i < n;i++) {
for (j = 0;j < n;j++) {
if (i != j) {
k = (long) (coord[0] - coord[j][0]);
l = (long) (coord[1] - coord[j][1]);
matrix[j] = k * k + l * l;
}
}
}
for (i = 0;i < n;i++) {
for (j = 0;j < n;j++) {
for (k = 0;k < n;k++) {
if ((i != j) && (j != k) && (i != k))
if (matrix[k] > max(matrix[j],matrix[j][k]))
matrix[k] = max(matrix[j],matrix[j][k]);
}
}
}
printf("Scenario #%d\n",count);
printf("Frog Distance = %.3lf\n\n",sqrt((double)matrix[0][1]));
count++;
}
}
[/c]
[c]
#include <stdio.h>
#include <string.h>
#include <math.h>
int n,i,j,count = 1;
long k,l;
int coord[200][2];
long matrix[200][200];
long max(long a,long b) {
if (a < b) return b;
else return a;
}
int main () {
while (1) {
scanf("%d",&n);
if (n == 0) return 0;
memset(matrix,0,sizeof(matrix));
for (i = 0;i < n;i++) scanf("%d %d",&coord[0],&coord[1]);
for (i = 0;i < n;i++) {
for (j = 0;j < n;j++) {
if (i != j) {
k = (long) (coord[0] - coord[j][0]);
l = (long) (coord[1] - coord[j][1]);
matrix[j] = k * k + l * l;
}
}
}
for (i = 0;i < n;i++) {
for (j = 0;j < n;j++) {
for (k = 0;k < n;k++) {
if ((i != j) && (j != k) && (i != k))
if (matrix[k] > max(matrix[j],matrix[j][k]))
matrix[k] = max(matrix[j],matrix[j][k]);
}
}
}
printf("Scenario #%d\n",count);
printf("Frog Distance = %.3lf\n\n",sqrt((double)matrix[0][1]));
count++;
}
}
[/c]
Can someone please either give me some cases or help check my code, because my solution got wa even though the implementation is correct
[c]
#include <stdio.h>
#include <string.h>
#include <math.h>
int n,i,j,count = 1;
long k,l;
int coord[200][2];
long matrix[200][200];
long max(long a,long b) {
if (a < b) return b;
else return a;
}
int main () {
while (1) {
scanf("%d",&n);
if (n == 0) return 0;
memset(matrix,0,sizeof(matrix));
for (i = 0;i < n;i++) scanf("%d %d",&coord[0],&coord[1]);
for (i = 0;i < n;i++) {
for (j = 0;j < n;j++) {
if (i != j) {
k = (long) (coord[0] - coord[j][0]);
l = (long) (coord[1] - coord[j][1]);
matrix[j] = k * k + l * l;
}
}
}
for (i = 0;i < n;i++) {
for (j = 0;j < n;j++) {
for (k = 0;k < n;k++) {
if ((i != j) && (j != k) && (i != k))
if (matrix[k] > max(matrix[j],matrix[j][k]))
matrix[k] = max(matrix[j],matrix[j][k]);
}
}
}
printf("Scenario #%d\n",count);
printf("Frog Distance = %.3lf\n\n",sqrt((double)matrix[0][1]));
count++;
}
}
[/c]
[c]
#include <stdio.h>
#include <string.h>
#include <math.h>
int n,i,j,count = 1;
long k,l;
int coord[200][2];
long matrix[200][200];
long max(long a,long b) {
if (a < b) return b;
else return a;
}
int main () {
while (1) {
scanf("%d",&n);
if (n == 0) return 0;
memset(matrix,0,sizeof(matrix));
for (i = 0;i < n;i++) scanf("%d %d",&coord[0],&coord[1]);
for (i = 0;i < n;i++) {
for (j = 0;j < n;j++) {
if (i != j) {
k = (long) (coord[0] - coord[j][0]);
l = (long) (coord[1] - coord[j][1]);
matrix[j] = k * k + l * l;
}
}
}
for (i = 0;i < n;i++) {
for (j = 0;j < n;j++) {
for (k = 0;k < n;k++) {
if ((i != j) && (j != k) && (i != k))
if (matrix[k] > max(matrix[j],matrix[j][k]))
matrix[k] = max(matrix[j],matrix[j][k]);
}
}
}
printf("Scenario #%d\n",count);
printf("Frog Distance = %.3lf\n\n",sqrt((double)matrix[0][1]));
count++;
}
}
[/c]
Can someone please either give me some cases or help check my code, because my solution got wa even though the implementation is correct
Code: Select all
#include <stdio.h>
#include <string.h>
#include <math.h>
int n,i,j,count = 1;
long k,l;
int coord[200][2];
long matrix[200][200];
long max(long a,long b) {
if (a < b) return b;
else return a;
}
int main () {
while (1) {
scanf("%d",&n);
if (n == 0) return 0;
memset(matrix,0,sizeof(matrix));
for (i = 0;i < n;i++) scanf("%d %d",&coord[i][0],&coord[i][1]);
for (i = 0;i < n;i++) {
for (j = 0;j < n;j++) {
if (i != j) {
k = (long) (coord[i][0] - coord[j][0]);
l = (long) (coord[i][1] - coord[j][1]);
matrix[i][j] = k * k + l * l;
}
}
}
for (i = 0;i < n;i++) {
for (j = 0;j < n;j++) {
for (k = 0;k < n;k++) {
if ((i != j) && (j != k) && (i != k))
if (matrix[i][k] > max(matrix[i][j],matrix[j][k]))
matrix[i][k] = max(matrix[i][j],matrix[j][k]);
}
}
}
printf("Scenario #%d\n",count);
printf("Frog Distance = %.3lf\n\n",sqrt((double)matrix[0][1]));
count++;
}
}
534-frogger- help!
What is output for:
5
1 0
2 0
3 0
4 0
4 1
I need more test cases. Please help!
5
1 0
2 0
3 0
4 0
4 1
I need more test cases. Please help!
534
Please help me.Tell me where I'm worong.
I use Floyd Warshal's algoritm.
[pascal] Deleted...[/pascal]
I use Floyd Warshal's algoritm.
[pascal] Deleted...[/pascal]
Last edited by Eduard on Thu Apr 08, 2004 6:23 pm, edited 1 time in total.
someone who like to solve informatic problems.
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650
I find my bag ... at the beginning matrix must be infinity(like a maxlongint) not 0.
someone who like to solve informatic problems.
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650
-
- New poster
- Posts: 28
- Joined: Mon Mar 01, 2004 11:29 pm
534: Why wrong? Is MST solution?
Hi,
I tried to solve the 534 and implemented MST-Kruskal and nothing.
Do Problem want to know the minimax jumpy? Ok?
Have Someone input for test?
My Code:
[cpp]
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MAX_VERTICES 205
#define MAX_ARESTAS 206*206
#define INFINITO 1000000000000.0
typedef struct {
int x, y;
} Ponto;
typedef struct {
int u, v;
bool usada;
double peso;
} Aresta;
Aresta arestas[MAX_ARESTAS]; // Conjunto de Arestas
int id[MAX_VERTICES]; // id da componente que o vertice esta
int sz[MAX_VERTICES]; // Tamanho da componente
int numArestas; // N
I tried to solve the 534 and implemented MST-Kruskal and nothing.
Do Problem want to know the minimax jumpy? Ok?
Have Someone input for test?
My Code:
[cpp]
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MAX_VERTICES 205
#define MAX_ARESTAS 206*206
#define INFINITO 1000000000000.0
typedef struct {
int x, y;
} Ponto;
typedef struct {
int u, v;
bool usada;
double peso;
} Aresta;
Aresta arestas[MAX_ARESTAS]; // Conjunto de Arestas
int id[MAX_VERTICES]; // id da componente que o vertice esta
int sz[MAX_VERTICES]; // Tamanho da componente
int numArestas; // N