Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved 4 problems + Graphs #52

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions Algoritms/Olympiada 2023-2024/Anton_and_watermelons.cpp
Copy link
Contributor

Choose a reason for hiding this comment

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

Использование векторов - кринге

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2022 Zener
// Шаблон для олимпиадных задач

#include <bits/stdc++.h>

using namespace std;

void solve();

int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);

#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("error.txt", "w", stderr);
freopen("output.txt", "w", stdout);
#endif

int t = 1;
// /*is Single Test case?*/ cin >> t;
while (t--) {
solve();
cout << "\n";
}

cerr << "time taken : " << (float) clock() / CLOCKS_PER_SEC << " secs" << endl;
return 0;
}

void solve() {
long long n, m, d, temp;
cin >> n >> m >> d;
vector<long long> vec_x;
vector<long long> vec_y;
for(int i = 0; i < d; ++i){
cin >> temp;
vec_x.push_back(temp);
cin >> temp;
vec_y.push_back(temp);
}
long long x = vec_x[0], y = vec_y[0];
for(int i = 0; i < d; ++i){
x = min(x, vec_x[i]);
y = min(y, vec_y[i]);
}
cout << x * y << " " << d;
}
46 changes: 46 additions & 0 deletions Algoritms/Olympiada 2023-2024/Colored_cube.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2022 Zener
// Шаблон для олимпиадных задач

#include <bits/stdc++.h>

using namespace std;

void solve();

int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);

#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("error.txt", "w", stderr);
freopen("output.txt", "w", stdout);
#endif

int t = 1;
// /*is Single Test case?*/ cin >> t;
while (t--) {
solve();
cout << "\n";
}

cerr << "time taken : " << (float) clock() / CLOCKS_PER_SEC << " secs" << endl;
return 0;
}

void solve() {
int n, f;
cin >> n >> f;
if(f == 0){
cout << (n - 2) * (n - 2);
}
else if(f == 1){
cout << (n - 2) * (n - 2) * 6;
}
else if(f == 2){
cout << (n - 2) * 12;
}
else if(f == 3){
cout << 8;
}
}
45 changes: 45 additions & 0 deletions Algoritms/Olympiada 2023-2024/Triangle_of_sticks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2022 Zener
// Шаблон для олимпиадных задач

#include <bits/stdc++.h>

using namespace std;

void solve();

int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);

#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("error.txt", "w", stderr);
freopen("output.txt", "w", stdout);
#endif

int t = 1;
// /*is Single Test case?*/ cin >> t;
while (t--) {
solve();
cout << "\n";
}

cerr << "time taken : " << (float) clock() / CLOCKS_PER_SEC << " secs" << endl;
return 0;
}

void solve() {
long long a, b, c;
cin >> a >> b >> c;
long long x;
x = max(max(a, b), c);
if(a == x){
cout << b + c - a;
}
else if(b == x){
cout << a + c - b;
}
else{
cout << a + b - c;
}
}
46 changes: 46 additions & 0 deletions Algoritms/Olympiada 2023-2024/paid_musical_services.cpp
Copy link
Contributor

Choose a reason for hiding this comment

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

Не проходит временное ограничение. Временная сложность большая

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2022 Zener
// Шаблон для олимпиадных задач

#include <bits/stdc++.h>

using namespace std;

void solve();

int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);

#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("error.txt", "w", stderr);
freopen("output.txt", "w", stdout);
#endif

int t = 1;
// /*is Single Test case?*/ cin >> t;
while (t--) {
solve();
cout << "\n";
}

cerr << "time taken : " << (float) clock() / CLOCKS_PER_SEC << " secs" << endl;
return 0;
}

void solve() {
long long n, m;
cin >> n >> m;
long long a = 1, d = 1, ans = 0;
while(d <= m){
if((a + (n - 1) * d) <= m){
ans += 1;
a += 1;
}
else{
d += 1;
a = 1;
}
}
cout << ans;
}
10 changes: 10 additions & 0 deletions Data_Structures/Graph/Graph.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// Created by User on 15.10.2023.
//

#include <bits/stdc++.h>
#include "Graph.h"

int main() {
cout << " ";
}
54 changes: 54 additions & 0 deletions Data_Structures/Graph/Graph.h
Copy link
Contributor

Choose a reason for hiding this comment

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

Так а где дз?

Copy link
Contributor

Choose a reason for hiding this comment

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

Тут ведь ошибки есть. Не нужно возвращать вершины, их достаточно возвращать
MinDist должнен быть приватным методом, если не должно использоваться вне метода поиска пути
Почему _edges превратились в матрицу? Это список ребер, а не матрица
Часть я не разобрал, но я думаю, что и так будет норм

Copy link
Contributor

Choose a reason for hiding this comment

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

Убери лишние детали - dfs здесь не нужен, нужен только алгоритм дейкстры

Copy link
Contributor

Choose a reason for hiding this comment

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

А еще remove_edge так и не доделан

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// Created by User on 15.10.2023.
//

#ifndef COMPETITIVE_PROGRAMMING_GRAPH_H
#define COMPETITIVE_PROGRAMMING_GRAPH_H

#include "Graph_Interface.h"
#include <algorithm>
#include <vector>

using namespace std;

template<typename V, typename E>
class Graph : public GraphInterface<V, E> {
vector<V> _vertexes;
vector<E> _edges;

public:
Graph() = default;

vector<V> vertexes() override {
return _vertexes;
}

vector<E> edges() override {
return _edges;
}

void add_vertex(V vertex) override {
_vertexes.push_back(vertex);
}

void add_edge(V v1, V v2) override {
_edges.push_back(E(v1, v2));
}

void remove_vertex(V vertex) override {
auto index = find(_vertexes.begin(), _vertexes.end(), vertex);
if (index != _vertexes.end()) _vertexes.erase(index);
}

void remove_edge(E edge) override {
// ДЗ
}

V *path(V v1, V v2) override {
// ДЗ - Поиск в ширину
return nullptr;
}
};


#endif //COMPETITIVE_PROGRAMMING_GRAPH_H
33 changes: 33 additions & 0 deletions Data_Structures/Graph/Graph_Interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// Created by Zener085 on 15.10.2023.
//

#ifndef COMPETITIVE_PROGRAMMING_GRAPH_INTERFACE_H
#define COMPETITIVE_PROGRAMMING_GRAPH_INTERFACE_H

#include <vector>

using namespace std;

template<typename V, typename E>
class GraphInterface {
/**
* Возвращает все узлы графа
* @return Массив узлов графа
*/
virtual vector<V> vertexes() = 0;

/**
* Возвращает все линии графа
* @return Массив линий графа
*/
virtual vector<E> edges() = 0;
virtual void add_vertex(V vertex) = 0;
virtual void add_edge(V v1, V v2) = 0;
virtual void remove_vertex(V vertex) = 0;
virtual void remove_edge(E edge) = 0;

virtual V *path(V v1, V v2) = 0;
};

#endif //COMPETITIVE_PROGRAMMING_GRAPH_INTERFACE_H