mam taki kod
#include <bits/stdc++.h>
using namespace std;
class Rock{
public:
double x;
double y;
vector<int> ids_rocks_possible_to_jump;
void add_to_rocks_possible_to_jump(int & possible_to_jump_rock_id){
ids_rocks_possible_to_jump.push_back(possible_to_jump_rock_id);
}
};
class Pond{
vector<Rock> rocks;
int id_frog_rock;
double frog_jump;
int id_the_farthest_rock_the_frog_can_jump_to = 0;
double the_farthest_distance = 0.0;
unordered_set<int>seen_rocks;
public:
Pond(){
int number_of_rocks;
cin >> number_of_rocks >> id_frog_rock >> frog_jump;
rocks.resize(number_of_rocks+1);
for (int i = 1; i <= number_of_rocks; i++)
cin >> rocks[i].x >> rocks[i].y;
}
double calculate_distance_between_rocks(Rock & rock1, Rock & rock2){
return sqrt((rock1.x - rock2.x) * (rock1.x - rock2.x) + (rock1.y - rock2.y) * (rock1.y - rock2.y));
}
bool can_jump(double distance){
return distance <= frog_jump;
}
void find_and_add_possible_to_jump_rocks(int & start_rock){
for (int rock_to_jump = 1; rock_to_jump < rocks.size(); rock_to_jump++)
if (can_jump(calculate_distance_between_rocks(rocks[start_rock], rocks[rock_to_jump])))
rocks[start_rock].add_to_rocks_possible_to_jump(rock_to_jump);
}
void add_conntections_betweeen_rocks(){
for (int rock_id = 1; rock_id < rocks.size(); rock_id++)
find_and_add_possible_to_jump_rocks(rock_id);
}
void find_the_farthest_rock_the_frog_can_jump_to(int & rock_id){
seen_rocks.insert(rock_id);
double distance = calculate_distance_between_rocks(rocks[id_frog_rock], rocks[rock_id]);
if (distance > the_farthest_distance){
the_farthest_distance = distance;
id_the_farthest_rock_the_frog_can_jump_to = rock_id;
}
for (int next_rock_id : rocks[rock_id].ids_rocks_possible_to_jump)
if (seen_rocks.count(next_rock_id) == false)
find_the_farthest_rock_the_frog_can_jump_to(next_rock_id);
}
void show_pond(){
for (int i = 1; i < rocks.size(); i++){
cout << i << " :";
for (int x : rocks[i].ids_rocks_possible_to_jump)
cout << x << " ";
cout << endl;
}
}
void calculate_the_farthest_distance(Rock & start_rock, Rock & the_farthest_rock){
vector<int> dirs = {1,0, -1,0, 0,1, 0,-1};
Rock new_rock;
for (int i = 0; i < dirs.size(); i += 2){
new_rock.x = the_farthest_rock.x + dirs[i] * frog_jump;
new_rock.y = the_farthest_rock.y + dirs[i+1] * frog_jump;
the_farthest_distance = max(the_farthest_distance, calculate_distance_between_rocks(start_rock, new_rock));
}
}
void calculate_and_show_the_farthest_distance(){
find_the_farthest_rock_the_frog_can_jump_to(id_frog_rock);
calculate_the_farthest_distance(rocks[id_frog_rock], rocks[id_the_farthest_rock_the_frog_can_jump_to]);
cout << fixed << setprecision(3) << the_farthest_distance;
}
};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
Pond pond;
pond.add_conntections_betweeen_rocks();
pond.calculate_and_show_the_farthest_distance();
return 0;
}
Jeśli mój kod jest bardzo nieczytelny to tak mniej więcej działa:
- Pobiera informacje o położeniach kamieni
- Sprawdza czy są możliwe połączenia między danymi kamieniami, jeśli są to dodaje połączenie tworząc graf
- DFS spaceruje po grafie i szukam najdalszego kamienia od kamienia początkowego
- Sprawdzam najdalszy punkt od kamienia startowego do miejsca do którego może doskoczyć żabka z skacząc najdalszego kamienia
Niestety sprawdzarka teraz jeśli mam błąd w teście wypisuje tylko Wrong answer, pomoże mi ktoś znaleźć testy dla których mój program daje zły wynik ?