Initial commit
This commit is contained in:
87
2019/republic/11_d1/bare.cpp
Normal file
87
2019/republic/11_d1/bare.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
#include <unordered_map>
|
||||
|
||||
using namespace std;
|
||||
|
||||
ifstream input_stream;
|
||||
ofstream output_stream;
|
||||
|
||||
|
||||
int getMinRest(int L, int lengths[], int K) {
|
||||
for (int i = 0; i < K; i++) {
|
||||
if (L % lengths[i] == 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
sort(lengths, lengths + K);
|
||||
for (int i = 1; i < K; i++) {
|
||||
if (lengths[i] - lengths[i - 1] == 1 && lengths[i] * lengths[i - 1] < L) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (K < 2) {
|
||||
return L % lengths[0];
|
||||
}
|
||||
|
||||
|
||||
set<int> processed_lengths;
|
||||
set<int> new_lengths;
|
||||
unordered_map<int, bool> detected_lengths;
|
||||
|
||||
for (int i = 0; i < K; i++) {
|
||||
processed_lengths.insert(lengths[i]);
|
||||
new_lengths.insert(lengths[i]);
|
||||
detected_lengths[lengths[i]] = true;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
// cout << "Processed: " << processed_lengths.size() << "; New: " << new_lengths.size() << endl;
|
||||
set<int> found_lengths;
|
||||
|
||||
for (auto i: processed_lengths) {
|
||||
for (auto j: new_lengths) {
|
||||
int new_len = i + j;
|
||||
if (new_len <= L && detected_lengths[new_len] == false) {
|
||||
found_lengths.insert(new_len);
|
||||
detected_lengths[new_len] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
processed_lengths.insert(new_lengths.begin(), new_lengths.end());
|
||||
if (found_lengths.size() == 0) {
|
||||
break;
|
||||
}
|
||||
new_lengths = found_lengths;
|
||||
}
|
||||
|
||||
auto m = processed_lengths.end();
|
||||
m--;
|
||||
return L - *m;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
input_stream.open("input.txt");
|
||||
|
||||
int L, K;
|
||||
input_stream >> L;
|
||||
input_stream >> K;
|
||||
|
||||
int lengths[K];
|
||||
for (int i = 0; i < K; i++) {
|
||||
input_stream >> lengths[i];
|
||||
}
|
||||
|
||||
cout << getMinRest(L, lengths, K) << endl;
|
||||
|
||||
input_stream.close();
|
||||
return 0;
|
||||
}
|
||||
BIN
2019/republic/11_d1/condition.pdf
Normal file
BIN
2019/republic/11_d1/condition.pdf
Normal file
Binary file not shown.
111
2019/republic/11_d1/sobol.cpp
Normal file
111
2019/republic/11_d1/sobol.cpp
Normal file
@@ -0,0 +1,111 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <unordered_map>
|
||||
|
||||
using namespace std;
|
||||
|
||||
ifstream input_stream;
|
||||
ofstream output_stream;
|
||||
|
||||
|
||||
struct Node {
|
||||
public:
|
||||
uint32_t number;
|
||||
Node *left, *right;
|
||||
|
||||
Node(uint32_t n):number(n) {
|
||||
}
|
||||
|
||||
Node(): number(0) {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
bool locateLeftmostNode (Node *node, uint32_t level, uint32_t targetLevel) {
|
||||
if (level == targetLevel) {
|
||||
cout << node -> number << " ";
|
||||
return 1;
|
||||
} else {
|
||||
// Search left. If unsuccessfull, search through right
|
||||
if (node -> left != nullptr) {
|
||||
if (locateLeftmostNode(node -> left, level + 1, targetLevel)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Search right. If unsuccessful, this should return 0
|
||||
if (node -> right != nullptr) {
|
||||
return locateLeftmostNode(node -> right, level + 1, targetLevel);
|
||||
}
|
||||
|
||||
// Previous searches didn't return anything, meaning node has no children. Return 0
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool locateRightmostNode (Node *node, uint32_t level, uint32_t targetLevel) {
|
||||
if (level == targetLevel) {
|
||||
cout << node -> number << endl;
|
||||
return 1;
|
||||
} else {
|
||||
// Search right. If unsuccessfull, search through left
|
||||
if (node -> right != nullptr) {
|
||||
if (locateRightmostNode(node -> right, level + 1, targetLevel)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Search left. If unsuccessful, this should return 0
|
||||
if (node -> left != nullptr) {
|
||||
return locateRightmostNode(node -> left, level + 1, targetLevel);
|
||||
}
|
||||
|
||||
// Previous searches didn't return anything, meaning node has no children. Return 0
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
input_stream.open("input.txt");
|
||||
|
||||
uint32_t N;
|
||||
uint16_t K;
|
||||
input_stream >> N;
|
||||
input_stream >> K;
|
||||
|
||||
unordered_map<uint32_t, Node*> orphanNodes;
|
||||
Node *nodes[N];
|
||||
|
||||
for (uint32_t i = 0; i < N; i++) {
|
||||
nodes[i] = new Node(i + 1);
|
||||
orphanNodes[i + 1] = nodes[i];
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < (N - 1); i++) {
|
||||
uint32_t parentId, childId;
|
||||
char direction;
|
||||
|
||||
input_stream >> parentId;
|
||||
input_stream >> childId;
|
||||
input_stream >> direction;
|
||||
|
||||
// Remove orphan mark from child
|
||||
orphanNodes.erase(childId);
|
||||
|
||||
// Assign child to parent
|
||||
if(direction == 'S') {
|
||||
nodes[parentId - 1] -> left = nodes[childId - 1];
|
||||
} else {
|
||||
nodes[parentId - 1] -> right = nodes[childId - 1];
|
||||
}
|
||||
}
|
||||
|
||||
Node *rootNode = orphanNodes.begin() -> second;
|
||||
locateLeftmostNode(rootNode, 0, K);
|
||||
locateRightmostNode(rootNode, 0, K);
|
||||
|
||||
input_stream.close();
|
||||
return 0;
|
||||
}
|
||||
60
2019/republic/11_d1/unsolved_arena.cpp
Normal file
60
2019/republic/11_d1/unsolved_arena.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
ifstream input_stream;
|
||||
|
||||
|
||||
struct Point
|
||||
{
|
||||
double x;
|
||||
double y;
|
||||
Point(double i, double j): x(i), y(j) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
double getDistance(Point *p1, Point *p2) {
|
||||
double x_distance = abs(p1 -> x - p2 -> x);
|
||||
double y_distance = abs(p1 -> y - p2 -> y);
|
||||
return pow(x_distance, 2) + pow(y_distance, 2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint16_t findSides(Point *points[3]) {
|
||||
double d1 = getDistance(points[0], points[1]);
|
||||
double d2 = getDistance(points[0], points[2]);
|
||||
double d3 = getDistance(points[1], points[2]);
|
||||
|
||||
if (d1 == d2 && d1 == d3) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
input_stream.open("input.txt");
|
||||
|
||||
Point *points[3];
|
||||
|
||||
for (uint8_t i = 0; i < 3; i++) {
|
||||
double tmp_x, tmp_y;
|
||||
input_stream >> tmp_x;
|
||||
input_stream >> tmp_y;
|
||||
|
||||
points[i] = new Point(tmp_x, tmp_y);
|
||||
}
|
||||
|
||||
cout << findSides(points) << endl;
|
||||
|
||||
input_stream.close();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user