Compare commits
No commits in common. "98b3a215821369bf2d02a234e0a6de3716c57c84" and "83862fb7bce6764521f256ab25a8b3ea222f7251" have entirely different histories.
98b3a21582
...
83862fb7bc
22 changed files with 0 additions and 1088 deletions
|
@ -1,79 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
/*O(n*log(n) + n), сортировка плюс проход по массиву заявок */
|
|
||||||
|
|
||||||
/* Структура для хранения зявки */
|
|
||||||
typedef struct application {
|
|
||||||
int begin;
|
|
||||||
int end;
|
|
||||||
} app;
|
|
||||||
|
|
||||||
int vector_compare(const void *a, const void *b);
|
|
||||||
app* solve(app* vector, unsigned int* NUM);
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
/* Число заявок */
|
|
||||||
unsigned int N;
|
|
||||||
scanf("%d", &N);
|
|
||||||
app* vector = (app*)calloc(N, sizeof(app));
|
|
||||||
|
|
||||||
/* Считываем информацию о заявках, начало-конец */
|
|
||||||
for (unsigned int i = 0; i < N; i++) {
|
|
||||||
scanf("%d %d", &vector[i].begin, &vector[i].end);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Сортируем заявки по времени окончания */
|
|
||||||
qsort(vector, N, sizeof(app), vector_compare);
|
|
||||||
|
|
||||||
/* Указатель на vector заменится, N изменится */
|
|
||||||
vector = solve(vector, &N);
|
|
||||||
|
|
||||||
printf("Решение:\nКоличество выполненных заявок:%d\n", N);
|
|
||||||
for (unsigned int i = 0; i < N; i++) {
|
|
||||||
printf("%i %i\n", vector[i].begin, vector[i].end);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(vector);
|
|
||||||
}
|
|
||||||
|
|
||||||
int vector_compare(const void *a, const void *b) {
|
|
||||||
return ((const app *)a)->end - ((const app *)b)->end;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Учитываем, что время не может быть отрицательным, тем самым
|
|
||||||
избавляясь от надобности создавать три указателя или же
|
|
||||||
прибегать к сложной сортировке */
|
|
||||||
|
|
||||||
app *solve(app *vector, unsigned int *N) {
|
|
||||||
/* Сохраняем начальное значение N */
|
|
||||||
unsigned int N_init = *N;
|
|
||||||
/* Конец очередной заявки */
|
|
||||||
int end = vector[0].end;
|
|
||||||
for (unsigned int i = 1; i < N_init; i++) {
|
|
||||||
if (end > vector[i].begin) {
|
|
||||||
/* Удаляем заявки, время начала которых раньше времени конца */
|
|
||||||
vector[i].begin = vector[i].end = -1;
|
|
||||||
/* Изменяем количество заявок */
|
|
||||||
(*N)--;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
/* Иначе, обновляем значение очередного конца */
|
|
||||||
end = vector[i].end;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
app* vector_res = (app*)calloc(*N, sizeof(app));
|
|
||||||
unsigned int j = 0;
|
|
||||||
/* Два случая: нужные заявки в конце, нужные заявки в начале */
|
|
||||||
for (unsigned int i = 0; i < N_init && j != *N; i++) {
|
|
||||||
/* Если заявка не помечена недействительной, то вписываем ее в новый массив */
|
|
||||||
if (vector[i].begin != -1) {
|
|
||||||
vector_res[j] = vector[i];
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
free(vector);
|
|
||||||
return vector_res;
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
# 1
|
|
||||||
|
|
||||||
5
|
|
||||||
1 2
|
|
||||||
3 6
|
|
||||||
3 4
|
|
||||||
5 7
|
|
||||||
1 7
|
|
||||||
|
|
||||||
# 2
|
|
||||||
|
|
||||||
3
|
|
||||||
1 5
|
|
||||||
2 3
|
|
||||||
3 4
|
|
|
@ -1,120 +0,0 @@
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <limits.h>
|
|
||||||
|
|
||||||
/* O(n^2) */
|
|
||||||
|
|
||||||
int* solve(int** massiv, int n, int x); // 0 вершина(можно заменить в коде)
|
|
||||||
void route(int** massiv, int* problem, int n, int x);// для 0 вершины
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
int n;
|
|
||||||
int x;
|
|
||||||
|
|
||||||
scanf("%d", &n);
|
|
||||||
int **adj = (int**)calloc(n, sizeof(int*));
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
adj[i] = (int*)calloc(n, sizeof(int));
|
|
||||||
}
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
for (int j = 0; j < n; j++) {
|
|
||||||
scanf("%d", &adj[i][j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Номер вершины */
|
|
||||||
scanf("%d", &x);
|
|
||||||
|
|
||||||
int *res = solve(adj, n, x);
|
|
||||||
|
|
||||||
route(adj, res, n, x);
|
|
||||||
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
free(adj[i]);
|
|
||||||
}
|
|
||||||
free(adj);
|
|
||||||
|
|
||||||
free(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
int *solve(int **adj, int n, int x) {
|
|
||||||
/* Пройденные вершины - 1, непройденные - 0 */
|
|
||||||
int *vertics = (int*)calloc(n, sizeof(int));
|
|
||||||
/* Вершины, из которых быстрее всего добраться */
|
|
||||||
int *res = (int*)calloc(n, sizeof(int));
|
|
||||||
/* Количество пройденных вершин */
|
|
||||||
int size = 1;
|
|
||||||
/* Массив с длинами ребер, из которых выбираем */
|
|
||||||
int* arr = (int*)calloc(n, sizeof(int));
|
|
||||||
/* Начальная вершина */
|
|
||||||
int vertic = x;
|
|
||||||
/* Делаем начальную вершину выбранной */
|
|
||||||
vertics[vertic] = 1;
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
arr[i] = adj[vertic][i];
|
|
||||||
res[i] = vertic;
|
|
||||||
}
|
|
||||||
while (size != n) {
|
|
||||||
int min = INT_MAX;
|
|
||||||
int k;
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
/* Пропускаем пройденные вершины */
|
|
||||||
if (vertics[i] == 1) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/* Ищем вершину, до которой ближе всего (с номером k) */
|
|
||||||
if (min > arr[i]) {
|
|
||||||
min = arr[i];
|
|
||||||
k = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Отмечаем найденную вершину "пройденной" */
|
|
||||||
vertics[k] = 1;
|
|
||||||
/* Смотрим, изменится ли наш массив рёбер, если будем "шагать" из выбранной вершины */
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
/* Игнорируем пройденные вершины */
|
|
||||||
if (vertics[i] == 1) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/* Если из вершины k ближе до вершины i, то обновляем знaчение для i */
|
|
||||||
if (arr[i] > min + adj[k][i]) {
|
|
||||||
arr[i] = min + adj[k][i];
|
|
||||||
res[i] = k;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
size++;
|
|
||||||
}
|
|
||||||
free(vertics);
|
|
||||||
free(arr);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
void route(int **adj, int *res, int n, int x) {
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
/* Игнорируем петли */
|
|
||||||
if (i == x) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
int w = i;
|
|
||||||
/* Суммарная длина */
|
|
||||||
int sum = 0;
|
|
||||||
/* Если есть прямой короткий путь, то выводим его */
|
|
||||||
if (res[i] == x) {
|
|
||||||
sum = adj[x][i];
|
|
||||||
printf("%d: %d-%d\n", i, i, x);
|
|
||||||
}
|
|
||||||
/* Иначе, последовательно идем по вершинам из res */
|
|
||||||
else {
|
|
||||||
printf("%d: %d-", i, i);
|
|
||||||
while (res[w] != x) {
|
|
||||||
sum += adj[res[w]][w];
|
|
||||||
printf("%d-", res[w]);
|
|
||||||
w = res[w];
|
|
||||||
}
|
|
||||||
sum += adj[x][w];
|
|
||||||
printf("%d\n", x);
|
|
||||||
}
|
|
||||||
printf("Расстояние: %d\n###\n", sum);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
8
|
|
||||||
0 23 12 999 999 999 999 999
|
|
||||||
23 0 25 999 22 999 999 35
|
|
||||||
12 25 0 18 999 999 999 999
|
|
||||||
999 999 18 0 999 20 999 999
|
|
||||||
999 22 999 999 0 23 14 999
|
|
||||||
999 999 999 20 23 0 24 999
|
|
||||||
999 999 999 999 14 24 0 16
|
|
||||||
999 35 999 999 999 999 16 0
|
|
||||||
4
|
|
|
@ -1,91 +0,0 @@
|
||||||
#define _CRT_SECURE_NO_WARNINGS
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <limits.h>
|
|
||||||
|
|
||||||
/* O(n^2), n - количество вершин, используем матрицу смежности */
|
|
||||||
|
|
||||||
void solve(int **adj, int **res, int n);
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
int n;
|
|
||||||
|
|
||||||
scanf("%d", &n);
|
|
||||||
int **adj = (int**)calloc(n, sizeof(int*));
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
adj[i] = (int*)calloc(n, sizeof(int));
|
|
||||||
}
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
for (int j = 0; j < n; j++) {
|
|
||||||
scanf("%d", &adj[i][j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int **res = (int**)calloc(n, sizeof(int*));
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
res[i] = (int*)calloc(n, sizeof(int));
|
|
||||||
}
|
|
||||||
|
|
||||||
solve(adj, res, n);
|
|
||||||
|
|
||||||
printf("Решение:\n");
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
for (int j = i + 1; j < n; j++) {
|
|
||||||
if (res[i][j] != 0) {
|
|
||||||
printf("%i-%i: %i\n", i, j, res[i][j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Освобождаем память */
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
free(adj[i]);
|
|
||||||
}
|
|
||||||
free(adj);
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
free(res[i]);
|
|
||||||
}
|
|
||||||
free(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
void solve(int **adj, int **res, int n) {
|
|
||||||
/* Множество выбранных вершин, 1 - выбрано, 0 - не выбрано */
|
|
||||||
int* set = (int *)calloc(n, sizeof(int));
|
|
||||||
/* Выбрали первую вершину */
|
|
||||||
set[0] = 1;
|
|
||||||
/* Количество выбранных вершин */
|
|
||||||
int set_size = 1;
|
|
||||||
while (set_size != n) {
|
|
||||||
/* "Бесконечность" */
|
|
||||||
int min = INT_MAX;
|
|
||||||
/* Номер вершины */
|
|
||||||
int k_i;
|
|
||||||
int k_j;
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
/* Если вершина еще не выбрана, то пропускаем её */
|
|
||||||
if (!set[i]) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/* Рассматриваем выбранные вешины */
|
|
||||||
for (int j = 0; j < n; j++) {
|
|
||||||
/* Если вершина k_j выбрана, то пропускаем её, она уже в компоненте связности */
|
|
||||||
if (set[j] == 1) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/* Выбираем кратчайшее ребро */
|
|
||||||
if (min > adj[i][j] && adj[i][j]) {
|
|
||||||
min = adj[i][j];
|
|
||||||
k_i = i;
|
|
||||||
k_j = j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Добавляем вершину k_j в компоненту связности */
|
|
||||||
set[k_j] = 1;
|
|
||||||
/* Сохраняем в симметрическую матрицу результат */
|
|
||||||
res[k_i][k_j] = adj[k_i][k_j];
|
|
||||||
res[k_j][k_i] = adj[k_i][k_j];
|
|
||||||
set_size++;
|
|
||||||
}
|
|
||||||
free(set);
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
5
|
|
||||||
0 9 75 0 0
|
|
||||||
9 0 95 19 42
|
|
||||||
75 95 0 51 66
|
|
||||||
0 19 51 0 31
|
|
||||||
0 42 66 31 0
|
|
|
@ -1,78 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
/* O(n) - алгоритм Тарьяна */
|
|
||||||
int* solve(int** massiv, int n);
|
|
||||||
void dfs(int** massiv, int size, int* paint, int vertex, int* problem, int* len);
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
int n;
|
|
||||||
|
|
||||||
scanf("%d", &n);
|
|
||||||
int **adj = (int**)calloc(n, sizeof(int*));
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
adj[i] = (int*)calloc(n, sizeof(int));
|
|
||||||
}
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
for (int j = 0; j < n; j++) {
|
|
||||||
scanf("%d", &adj[i][j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int *res = solve(adj, n);
|
|
||||||
|
|
||||||
for (int i = 0; i < n; ++i) {
|
|
||||||
printf("%d ", res[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Освобождаем память */
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
free(adj[i]);
|
|
||||||
}
|
|
||||||
free(adj);
|
|
||||||
free(res);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int* solve(int** adj, int n) {
|
|
||||||
int* res = (int*)calloc(n, sizeof(int));
|
|
||||||
/* Список раскрасок вершин, 0 - белый, 1 - серый, 2 - черный */
|
|
||||||
int* paint = (int*)calloc(n, sizeof(int));
|
|
||||||
int len = n - 1;
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
if (paint[i] == 0) {
|
|
||||||
dfs(adj, n, paint, i, res, &len);
|
|
||||||
}
|
|
||||||
/* Если нашлась серая вершина на данном шаге, то граф цикличен */
|
|
||||||
else if (paint[i] == 1) {
|
|
||||||
printf("Граф цикличен, решения не существует:\n");
|
|
||||||
assert(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
free(paint);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
void dfs(int **adj, int size, int* paint, int vertex, int* res, int* len) {
|
|
||||||
if (paint[vertex] == 0) {
|
|
||||||
/* Красим белую вершину в серую */
|
|
||||||
paint[vertex] = 1;
|
|
||||||
/* вызываем поиск в глубину для каждой вершины, в которую можем дойти из данной, рекурсивно */
|
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
if (adj[vertex][i] == 1) {
|
|
||||||
dfs(adj, size, paint, i, res, len);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Заносим вершину в список для вывода */
|
|
||||||
res[(*len)--] = vertex;
|
|
||||||
/* Красим вершину в черный, она обработана */
|
|
||||||
paint[vertex] = 2;
|
|
||||||
|
|
||||||
}
|
|
||||||
/* Если нашлась серая вершина - граф цикличен */
|
|
||||||
else if (paint[vertex] == 1) {
|
|
||||||
printf("Граф цикличен, решения не существует:\n");
|
|
||||||
assert(0);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
6
|
|
||||||
0 0 0 0 0 1
|
|
||||||
1 0 0 0 0 0
|
|
||||||
0 0 0 0 0 0
|
|
||||||
1 0 1 0 0 0
|
|
||||||
0 0 1 0 0 0
|
|
||||||
0 0 0 0 0 0
|
|
|
@ -1,51 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
/* O(n^3) */
|
|
||||||
|
|
||||||
void solve(int** adj, int n);
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
int n;
|
|
||||||
scanf("%d", &n);
|
|
||||||
int **adj = (int**)calloc(n, sizeof(int*));
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
adj[i] = (int*)calloc(n, sizeof(int));
|
|
||||||
}
|
|
||||||
/* Считываем матрицу смежности. Вместо бесконечности выступает 9999 */
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
for (int j = 0; j < n; j++) {
|
|
||||||
scanf("%d", &adj[i][j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
solve(adj, n);
|
|
||||||
|
|
||||||
printf("Решение:\n");
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
for (int j = 0; j < n; j++) {
|
|
||||||
printf("%d ", adj[i][j]);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Освобождаем память */
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
free(adj[i]);
|
|
||||||
}
|
|
||||||
free(adj);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void solve(int **adj, int n) {
|
|
||||||
/* Перебираем все варианты добраться из i в j через k, если выходит короче, то перезаписываем значение i->j */
|
|
||||||
for (int k = 0; k < n; k++) {
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
for (int j = 0; j < n; j++) {
|
|
||||||
if (adj[i][k] + adj[k][j] < adj[i][j]) {
|
|
||||||
adj[i][j] = adj[i][k] + adj[k][j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
8
|
|
||||||
0 23 12 9999 9999 9999 9999 9999
|
|
||||||
23 0 25 9999 22 9999 9999 35
|
|
||||||
12 25 0 18 9999 9999 9999 9999
|
|
||||||
9999 9999 18 0 9999 20 9999 9999
|
|
||||||
9999 22 9999 9999 0 23 14 9999
|
|
||||||
9999 9999 9999 20 23 0 24 9999
|
|
||||||
9999 9999 9999 9999 14 24 0 16
|
|
||||||
9999 35 9999 9999 9999 9999 16 0
|
|
32
nasm/D.asm
32
nasm/D.asm
|
@ -1,32 +0,0 @@
|
||||||
extern printf
|
|
||||||
extern scanf
|
|
||||||
global main
|
|
||||||
|
|
||||||
section .text
|
|
||||||
main:
|
|
||||||
push y
|
|
||||||
push x
|
|
||||||
push nya1
|
|
||||||
call scanf
|
|
||||||
add esp, 12
|
|
||||||
|
|
||||||
mov eax, [x]
|
|
||||||
;mov ebx, [y]
|
|
||||||
cdq
|
|
||||||
idiv dword [y]
|
|
||||||
|
|
||||||
push eax
|
|
||||||
push nya
|
|
||||||
call printf
|
|
||||||
add esp, 8
|
|
||||||
|
|
||||||
xor eax, eax
|
|
||||||
ret
|
|
||||||
|
|
||||||
section .data
|
|
||||||
nya db "%d", 10, 0
|
|
||||||
nya1 db "%d %d", 0
|
|
||||||
|
|
||||||
section .bss
|
|
||||||
x resd 1
|
|
||||||
y resd 1
|
|
32
nasm/E.asm
32
nasm/E.asm
|
@ -1,32 +0,0 @@
|
||||||
extern printf
|
|
||||||
extern scanf
|
|
||||||
global main
|
|
||||||
|
|
||||||
section .text
|
|
||||||
main:
|
|
||||||
push y
|
|
||||||
push x
|
|
||||||
push nya1
|
|
||||||
call scanf
|
|
||||||
add esp, 12
|
|
||||||
|
|
||||||
mov eax, [x]
|
|
||||||
;mov ebx, [y]
|
|
||||||
cdq
|
|
||||||
idiv dword [y]
|
|
||||||
|
|
||||||
push edx
|
|
||||||
push nya
|
|
||||||
call printf
|
|
||||||
add esp, 8
|
|
||||||
|
|
||||||
xor eax, eax
|
|
||||||
ret
|
|
||||||
|
|
||||||
section .data
|
|
||||||
nya db "%d", 10, 0
|
|
||||||
nya1 db "%d %d", 0
|
|
||||||
|
|
||||||
section .bss
|
|
||||||
x resd 1
|
|
||||||
y resd 1
|
|
44
nasm/G64.asm
44
nasm/G64.asm
|
@ -1,44 +0,0 @@
|
||||||
global main
|
|
||||||
extern scanf
|
|
||||||
extern printf
|
|
||||||
section .text
|
|
||||||
|
|
||||||
main:
|
|
||||||
; scanf
|
|
||||||
sub rsp, 8
|
|
||||||
mov rdi, nya
|
|
||||||
mov rsi, x
|
|
||||||
mov rdx, y
|
|
||||||
call scanf wrt ..plt
|
|
||||||
add rsp, 8
|
|
||||||
|
|
||||||
; comparsion
|
|
||||||
mov rax, qword [rel x]
|
|
||||||
add rax, [rel y]
|
|
||||||
|
|
||||||
jb meow
|
|
||||||
push rbp
|
|
||||||
mov rdi, no
|
|
||||||
call printf wrt ..plt
|
|
||||||
pop rbp
|
|
||||||
|
|
||||||
jmp end
|
|
||||||
|
|
||||||
meow:
|
|
||||||
push rbp
|
|
||||||
mov rdi, yes
|
|
||||||
call printf wrt ..plt
|
|
||||||
pop rbp
|
|
||||||
|
|
||||||
end:
|
|
||||||
xor rax, rax
|
|
||||||
ret
|
|
||||||
|
|
||||||
section .data
|
|
||||||
nya dq "%llu %llu", 0
|
|
||||||
yes db "YES", 10, 0
|
|
||||||
no db "NO", 10, 0
|
|
||||||
|
|
||||||
section .bss
|
|
||||||
x resq 1
|
|
||||||
y resq 1
|
|
52
nasm/H.asm
52
nasm/H.asm
|
@ -1,52 +0,0 @@
|
||||||
global main
|
|
||||||
extern printf
|
|
||||||
extern scanf
|
|
||||||
|
|
||||||
section .text
|
|
||||||
main:
|
|
||||||
push x
|
|
||||||
push nya
|
|
||||||
call scanf
|
|
||||||
add esp, 8
|
|
||||||
|
|
||||||
push y
|
|
||||||
push nya
|
|
||||||
call scanf
|
|
||||||
add esp, 8
|
|
||||||
|
|
||||||
mov ebx, dword [x] ; a
|
|
||||||
mov ecx, dword [y] ; b
|
|
||||||
|
|
||||||
loop:
|
|
||||||
cmp ecx, 0 ; compare b
|
|
||||||
je end
|
|
||||||
|
|
||||||
mov eax, ebx ; move a to eax
|
|
||||||
cdq
|
|
||||||
div ecx ; a / b, remain in edx
|
|
||||||
mov ebx, ecx ; a = b
|
|
||||||
mov ecx, edx ; b = remain
|
|
||||||
|
|
||||||
jmp loop
|
|
||||||
end:
|
|
||||||
|
|
||||||
mov eax, dword [x]
|
|
||||||
mul dword [y]
|
|
||||||
cdq
|
|
||||||
div ebx
|
|
||||||
|
|
||||||
push eax
|
|
||||||
push nya
|
|
||||||
call printf
|
|
||||||
add esp, 8
|
|
||||||
|
|
||||||
xor eax, eax
|
|
||||||
ret
|
|
||||||
|
|
||||||
section .data
|
|
||||||
nya db "%u", 0
|
|
||||||
|
|
||||||
section .bss
|
|
||||||
x resd 1
|
|
||||||
y resd 1
|
|
||||||
|
|
59
nasm/I.asm
59
nasm/I.asm
|
@ -1,59 +0,0 @@
|
||||||
global main
|
|
||||||
extern printf
|
|
||||||
extern scanf
|
|
||||||
|
|
||||||
section .text
|
|
||||||
main:
|
|
||||||
; read N
|
|
||||||
push n
|
|
||||||
push read
|
|
||||||
call scanf
|
|
||||||
add esp ,8
|
|
||||||
|
|
||||||
; read loop for x
|
|
||||||
xor ebx, ebx
|
|
||||||
;mov bx, word [n]
|
|
||||||
loop1:
|
|
||||||
cmp bx, word [n]
|
|
||||||
je nya1
|
|
||||||
lea eax, [x + 2 * ebx]
|
|
||||||
dbg1: push eax
|
|
||||||
push read
|
|
||||||
call scanf
|
|
||||||
add esp, 8
|
|
||||||
dbg2: inc ebx
|
|
||||||
jmp loop1
|
|
||||||
|
|
||||||
nya1:
|
|
||||||
|
|
||||||
xor ebx, ebx
|
|
||||||
mov bx, word [n]
|
|
||||||
dec ebx
|
|
||||||
loop2:
|
|
||||||
cmp bx, 0
|
|
||||||
jl nya2
|
|
||||||
lea eax, [x + 2 * ebx]
|
|
||||||
;push word [eax]
|
|
||||||
mov dx, word [eax]
|
|
||||||
push edx
|
|
||||||
push write
|
|
||||||
call printf
|
|
||||||
add esp, 8
|
|
||||||
dec ebx
|
|
||||||
jmp loop2
|
|
||||||
|
|
||||||
nya2:
|
|
||||||
push EOL
|
|
||||||
call printf
|
|
||||||
add esp, 4
|
|
||||||
xor eax, eax
|
|
||||||
ret
|
|
||||||
|
|
||||||
section .data
|
|
||||||
read db "%hu", 0
|
|
||||||
write db "%hu ", 0
|
|
||||||
EOL db 10, 0
|
|
||||||
|
|
||||||
section .bss
|
|
||||||
n resw 1
|
|
||||||
x resw 10000
|
|
68
nasm/J.asm
68
nasm/J.asm
|
@ -1,68 +0,0 @@
|
||||||
global main
|
|
||||||
extern printf
|
|
||||||
extern scanf
|
|
||||||
extern qsort
|
|
||||||
|
|
||||||
section .text
|
|
||||||
main:
|
|
||||||
push n
|
|
||||||
push readn
|
|
||||||
call scanf
|
|
||||||
add esp, 8
|
|
||||||
|
|
||||||
xor ebx, ebx
|
|
||||||
loop1:
|
|
||||||
cmp ebx, dword [n]
|
|
||||||
je nya1
|
|
||||||
lea eax, [x + 4 * ebx]
|
|
||||||
|
|
||||||
push eax
|
|
||||||
push nya
|
|
||||||
call scanf
|
|
||||||
add esp, 8
|
|
||||||
|
|
||||||
inc ebx
|
|
||||||
jmp loop1
|
|
||||||
nya1:
|
|
||||||
push compare
|
|
||||||
push dword 4
|
|
||||||
push dword [n]
|
|
||||||
push x
|
|
||||||
call qsort
|
|
||||||
add esp, 16
|
|
||||||
|
|
||||||
xor ebx, ebx
|
|
||||||
loop2:
|
|
||||||
cmp ebx, dword [n]
|
|
||||||
je nya2
|
|
||||||
lea eax, [x + 4 * ebx]
|
|
||||||
|
|
||||||
push dword [eax]
|
|
||||||
push write
|
|
||||||
call printf
|
|
||||||
add esp, 8
|
|
||||||
inc ebx
|
|
||||||
jmp loop2
|
|
||||||
|
|
||||||
nya2:
|
|
||||||
xor eax, eax
|
|
||||||
ret
|
|
||||||
|
|
||||||
compare:
|
|
||||||
mov eax, [esp+4]
|
|
||||||
mov eax, dword [eax]
|
|
||||||
|
|
||||||
mov ebx, [esp + 8]
|
|
||||||
mov ebx, dword [ebx]
|
|
||||||
|
|
||||||
sub eax, ebx
|
|
||||||
ret
|
|
||||||
|
|
||||||
section .data
|
|
||||||
write db "%d ", 0
|
|
||||||
nya db "%d", 0
|
|
||||||
readn db "%d", 0
|
|
||||||
|
|
||||||
section .bss
|
|
||||||
n resd 1
|
|
||||||
x resd 10000
|
|
78
nasm/J1.asm
78
nasm/J1.asm
|
@ -1,78 +0,0 @@
|
||||||
global main
|
|
||||||
extern printf
|
|
||||||
extern scanf
|
|
||||||
extern qsort
|
|
||||||
|
|
||||||
section .text
|
|
||||||
main:
|
|
||||||
; read N
|
|
||||||
push n
|
|
||||||
push readn
|
|
||||||
call scanf
|
|
||||||
add esp ,8
|
|
||||||
|
|
||||||
; read loop for x
|
|
||||||
xor ebx, ebx
|
|
||||||
|
|
||||||
loop1:
|
|
||||||
cmp bx, word [n]
|
|
||||||
je nya1
|
|
||||||
lea eax, [x + 4 * ebx]
|
|
||||||
push eax
|
|
||||||
push nya
|
|
||||||
call scanf
|
|
||||||
add esp, 8
|
|
||||||
inc ebx
|
|
||||||
jmp loop1
|
|
||||||
|
|
||||||
nya1:
|
|
||||||
push compare
|
|
||||||
push dword 4
|
|
||||||
push dword [n]
|
|
||||||
push x
|
|
||||||
call qsort
|
|
||||||
add esp, 16
|
|
||||||
|
|
||||||
xor ebx, ebx
|
|
||||||
|
|
||||||
loop2:
|
|
||||||
cmp ebx, dword [n]
|
|
||||||
je nya2
|
|
||||||
lea eax, [x + 4 * ebx]
|
|
||||||
|
|
||||||
xor edx, edx
|
|
||||||
mov edx, dword [eax]
|
|
||||||
push edx
|
|
||||||
push write
|
|
||||||
call printf
|
|
||||||
add esp, 8
|
|
||||||
inc ebx
|
|
||||||
jmp loop2
|
|
||||||
|
|
||||||
nya2:
|
|
||||||
xor eax, eax
|
|
||||||
ret
|
|
||||||
|
|
||||||
compare:
|
|
||||||
xor edx, edx
|
|
||||||
xor ecx, ecx
|
|
||||||
lea eax, [esp+4]
|
|
||||||
mov eax, [eax]
|
|
||||||
mov ecx, dword [eax]
|
|
||||||
|
|
||||||
lea ebx, [esp+8]
|
|
||||||
mov ebx, [ebx]
|
|
||||||
mov edx, dword [ebx]
|
|
||||||
sub ecx, edx
|
|
||||||
;mov ax, cx
|
|
||||||
;cwde
|
|
||||||
mov eax, ecx
|
|
||||||
ret
|
|
||||||
|
|
||||||
section .data
|
|
||||||
write db "%d ", 0
|
|
||||||
nya db "%d", 0
|
|
||||||
readn db "%d", 0
|
|
||||||
section .bss
|
|
||||||
n resd 1
|
|
||||||
x resd 10000
|
|
33
nasm/K.asm
33
nasm/K.asm
|
@ -1,33 +0,0 @@
|
||||||
global main
|
|
||||||
extern scanf
|
|
||||||
extern printf
|
|
||||||
|
|
||||||
section .text
|
|
||||||
main:
|
|
||||||
|
|
||||||
push y
|
|
||||||
push x
|
|
||||||
push scan
|
|
||||||
call scanf
|
|
||||||
add esp, 12
|
|
||||||
|
|
||||||
fld dword [x]
|
|
||||||
fld dword [y]
|
|
||||||
fdiv
|
|
||||||
|
|
||||||
sub esp, 8
|
|
||||||
fst qword [esp]
|
|
||||||
push nya
|
|
||||||
call printf
|
|
||||||
add esp, 12
|
|
||||||
xor eax, eax
|
|
||||||
ret
|
|
||||||
|
|
||||||
section .data
|
|
||||||
scan db "%f%f", 0
|
|
||||||
nya db "%f", 10, 0
|
|
||||||
|
|
||||||
section .bss
|
|
||||||
x resd 1
|
|
||||||
y resd 1
|
|
||||||
|
|
34
nasm/K1.asm
34
nasm/K1.asm
|
@ -1,34 +0,0 @@
|
||||||
global main
|
|
||||||
extern scanf
|
|
||||||
extern printf
|
|
||||||
|
|
||||||
section .text
|
|
||||||
main:
|
|
||||||
|
|
||||||
push y
|
|
||||||
push x
|
|
||||||
push scan
|
|
||||||
call scanf
|
|
||||||
add esp, 12
|
|
||||||
|
|
||||||
fld tword [x]
|
|
||||||
fld tword [y]
|
|
||||||
fdiv
|
|
||||||
|
|
||||||
sub esp, 12
|
|
||||||
fstp tword [esp]
|
|
||||||
push nya
|
|
||||||
call printf
|
|
||||||
add esp, 16
|
|
||||||
xor eax, eax
|
|
||||||
ret
|
|
||||||
|
|
||||||
section .data
|
|
||||||
scan db "%llf%llf", 0
|
|
||||||
nya db "%llf", 10, 0
|
|
||||||
|
|
||||||
section .bss align=16
|
|
||||||
x rest 1
|
|
||||||
resw 1
|
|
||||||
y rest 1
|
|
||||||
|
|
30
nasm/M.asm
30
nasm/M.asm
|
@ -1,30 +0,0 @@
|
||||||
global main
|
|
||||||
extern scanf
|
|
||||||
extern printf
|
|
||||||
|
|
||||||
section .text
|
|
||||||
main:
|
|
||||||
|
|
||||||
push x
|
|
||||||
push scan
|
|
||||||
call scanf
|
|
||||||
add esp, 8
|
|
||||||
|
|
||||||
fld tword [x]
|
|
||||||
fabs
|
|
||||||
|
|
||||||
sub esp, 12
|
|
||||||
fstp tword [esp]
|
|
||||||
push nya
|
|
||||||
call printf
|
|
||||||
add esp, 16
|
|
||||||
xor eax, eax
|
|
||||||
ret
|
|
||||||
|
|
||||||
section .data
|
|
||||||
scan db "%llf", 0
|
|
||||||
nya db "%llf", 10, 0
|
|
||||||
|
|
||||||
section .bss align=16
|
|
||||||
x rest 1
|
|
||||||
|
|
130
nasm/N.asm
130
nasm/N.asm
|
@ -1,130 +0,0 @@
|
||||||
global main
|
|
||||||
extern scanf
|
|
||||||
extern printf
|
|
||||||
|
|
||||||
<<<<<<< Updated upstream
|
|
||||||
|
|
||||||
section .text
|
|
||||||
main:
|
|
||||||
xor ebx, ebx
|
|
||||||
|
|
||||||
loop1:
|
|
||||||
cmp ebx, 8
|
|
||||||
jge nya1
|
|
||||||
inc ebx
|
|
||||||
|
|
||||||
; read element
|
|
||||||
lea edx, [a + 1*ebx]
|
|
||||||
push edx
|
|
||||||
push template
|
|
||||||
call scanf
|
|
||||||
add esp, 8
|
|
||||||
|
|
||||||
push word [edx]
|
|
||||||
push output
|
|
||||||
call printf
|
|
||||||
add esp, 8
|
|
||||||
|
|
||||||
jmp loop1
|
|
||||||
|
|
||||||
nya1:
|
|
||||||
|
|
||||||
|
|
||||||
; xor ebx, ebx
|
|
||||||
;
|
|
||||||
;loop2:
|
|
||||||
; cmp ebx, 8
|
|
||||||
; jge nya2
|
|
||||||
; inc ebx
|
|
||||||
;
|
|
||||||
; ; read element
|
|
||||||
; push b
|
|
||||||
; push template
|
|
||||||
; call scanf
|
|
||||||
; add esp, 8
|
|
||||||
;
|
|
||||||
; jmp loop1
|
|
||||||
;
|
|
||||||
;nya1:
|
|
||||||
|
|
||||||
; xor ebx, ebx
|
|
||||||
;loop3:
|
|
||||||
; output
|
|
||||||
; push word [a]
|
|
||||||
; push output
|
|
||||||
; call printf
|
|
||||||
; add esp, 8
|
|
||||||
|
|
||||||
|
|
||||||
xor eax, eax
|
|
||||||
ret
|
|
||||||
|
|
||||||
section .data
|
|
||||||
template db "%d", 0
|
|
||||||
output db "%d", 10, 0
|
|
||||||
t db "%d", 10, 0
|
|
||||||
|
|
||||||
section .bss
|
|
||||||
a resw 8
|
|
||||||
b resw 8
|
|
||||||
=======
|
|
||||||
section .text
|
|
||||||
main:
|
|
||||||
xor ebx, ebx
|
|
||||||
loop1:
|
|
||||||
cmp ebx, 8
|
|
||||||
je nya1
|
|
||||||
lea eax, [a + ebx]
|
|
||||||
push eax
|
|
||||||
push input
|
|
||||||
call scanf
|
|
||||||
add esp, 8
|
|
||||||
inc ebx
|
|
||||||
jmp loop1
|
|
||||||
|
|
||||||
nya1:
|
|
||||||
xor ebx, ebx
|
|
||||||
loop2:
|
|
||||||
cmp ebx, 8
|
|
||||||
je nya2
|
|
||||||
lea eax, [b + ebx]
|
|
||||||
push eax
|
|
||||||
push input
|
|
||||||
call scanf
|
|
||||||
add esp, 8
|
|
||||||
inc ebx
|
|
||||||
jmp loop2
|
|
||||||
nya2:
|
|
||||||
movq mm0, [a]
|
|
||||||
movq mm1, [b]
|
|
||||||
paddsb mm0, mm1
|
|
||||||
movq [a], mm0
|
|
||||||
xor ebx, ebx
|
|
||||||
loop3:
|
|
||||||
cmp ebx, 8
|
|
||||||
je nya3
|
|
||||||
lea eax, [a + ebx]
|
|
||||||
mov dl, byte [eax]
|
|
||||||
push edx
|
|
||||||
push output
|
|
||||||
call printf
|
|
||||||
add esp, 8
|
|
||||||
inc ebx
|
|
||||||
jmp loop3
|
|
||||||
|
|
||||||
nya3:
|
|
||||||
push EOL
|
|
||||||
call printf
|
|
||||||
add esp, 4
|
|
||||||
dbg: xor eax, eax
|
|
||||||
ret
|
|
||||||
|
|
||||||
section .data
|
|
||||||
input dd "%hhu", 0
|
|
||||||
output dd "%hhu ", 0
|
|
||||||
EOL dd 10
|
|
||||||
|
|
||||||
section .bss
|
|
||||||
a resb 8
|
|
||||||
b resb 8
|
|
||||||
>>>>>>> Stashed changes
|
|
30
nasm/O.asm
30
nasm/O.asm
|
@ -1,30 +0,0 @@
|
||||||
global _start
|
|
||||||
|
|
||||||
section .text
|
|
||||||
_start:
|
|
||||||
; input
|
|
||||||
mov eax, 3
|
|
||||||
xor ebx, ebx
|
|
||||||
mov ecx, nya
|
|
||||||
mov edx, 1
|
|
||||||
int 0x80
|
|
||||||
|
|
||||||
; modification
|
|
||||||
mov ax, word [nya]
|
|
||||||
or ax, 0111b
|
|
||||||
mov [nya], ax
|
|
||||||
|
|
||||||
; output
|
|
||||||
mov eax, 4
|
|
||||||
mov ebx, 1
|
|
||||||
mov ecx, nya
|
|
||||||
mov edx, 1
|
|
||||||
int 0x80
|
|
||||||
|
|
||||||
; program exit
|
|
||||||
mov eax, 1 ; sys_exit = 1
|
|
||||||
xor ebx, ebx
|
|
||||||
int 0x80
|
|
||||||
|
|
||||||
section .bss
|
|
||||||
nya resb 1
|
|
Reference in a new issue