Skip to content

Comments

States#37

Open
Andrw-404 wants to merge 5 commits intomainfrom
hw11-states
Open

States#37
Andrw-404 wants to merge 5 commits intomainfrom
hw11-states

Conversation

@Andrw-404
Copy link
Owner

No description provided.

printf("\n\nTest failed!\n\n");
return -1;
}
int (*dist)[CITIES] = malloc(CITIES * sizeof * dist);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это типа двумерный массив? Если я без идей, как это компилируется, то лучше так не писать :) Ну и не сокращайте имена никогда.

}

int visited[100] = { 0 };
int capitals[100];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Неинициализированные массивы запрещены стайлгайдом

int m = 0;
int k = 0;

const char filename[100] = "file.txt";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const char filename[100] = "file.txt";
const char filename[] = "file.txt";

Вам же не важно, что именно 100

Comment on lines +23 to +25
int n = 0;
int m = 0;
int k = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я там выше писал "не сокращайте имена", не догадываясь об этом ужасе. Даже если n, m и k были в условии, им в программе стоит дать говорящие и понятные имена, чтобы при чтении программы не надо было условие искать


const char filename[100] = "file.txt";
readFromFile(filename, &n, &m, &k, capitals, dist);
State* arrayWithState[100];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут тоже надо не забыть проинициалиизровать

void printStates(State** states, int k);

// Floyd-Warshell algorithm
void floydWarshall(int n, int dist[][CITIES]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут тоже. Хотя бы runFloydWarshall. И в комментарии опечатка в названии алгоритма


void initializationOfStates(State** arrayWithStates, int* capitals, int* visited, int k) {
for (int i = 0; i < k; i++) {
visited[capitals[i]] = 1;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

visited мог бы быть булевым, судя по всему

void initializationOfStates(State** arrayWithStates, int* capitals, int* visited, int k) {
for (int i = 0; i < k; i++) {
visited[capitals[i]] = 1;
arrayWithStates[i] = (State*)malloc(sizeof(State));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Проверьте успешность

void distributeCities(State** arrayWithStates, int n, int dist[][CITIES], int* visited, int k) {
for (int i = 0; i < n - k; ++i) {
for (int q = 0; q < k; ++q) {
int nearestCity = findNearestCity(arrayWithStates[q], n, dist, visited);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Просто ближайший город согласно предпосчитанной матрице дистанций брать нельзя, потому что кратчайший путь уже может быть занят другим государством. Например, положим, у нас две столицы, 1 и 2, и такой граф: (1) -- (2) -- ( ) -- ( ) — по условию задачи два свободных города должны отойти государству 2, у Вас один из них достанется 1. Тут алгоритм должен быть интеллектуальнее раза в два.


initializationOfStates(arrayWithState, capitals, visited, k);
floydWarshall(n, dist);
distributeCities(arrayWithState, n, dist, visited, k);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Что-то мы такой код уже видели в main. Вдруг в main ошибка? Тест её не поймает. Сделали бы отдельную функцию "взять граф из файла и посчитать", и её бы уже проверяли.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants