-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
} |
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; | ||
} | ||
} |
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; | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} |
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 << " "; | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Так а где дз? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут ведь ошибки есть. Не нужно возвращать вершины, их достаточно возвращать There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Убери лишние детали - dfs здесь не нужен, нужен только алгоритм дейкстры There was a problem hiding this comment. Choose a reason for hiding this commentThe 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,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 |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Использование векторов - кринге