commit f9a2e40404a8801077da6b9e9198aeec4aed1b81 Author: Yorick van Pelt Date: Sat Sep 24 21:16:39 2016 +0200 ... diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d3b6c5f --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +FILES := bapc-d bapc-a bapc-e bapc-j bapc-i bapc-f bapc-b +all: $(FILES) +clean: + rm -f $(FILES) +%: %.cpp + g++ -static -g -O2 -std=gnu++0x $< -o $@ + diff --git a/README.md b/README.md new file mode 100644 index 0000000..651d066 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +These are our solutions for the [BAPC](http://2015.bapc.eu/) preliminaries 2015. +See also the [problem set](http://2015.bapc.eu/problems/bapc-preliminaries-2015.tar.gz) + +Authors: +- Sal Wolffs +- Lars Jellema +- Yorick van Pelt diff --git a/bapc-a.cpp b/bapc-a.cpp new file mode 100644 index 0000000..11de7d9 --- /dev/null +++ b/bapc-a.cpp @@ -0,0 +1,33 @@ +#include +#include +#include + +bool is_square(long long x) { + return (round(sqrt(x)) * round(sqrt(x))) == x; +} + +int main(int argc, char const *argv[]) +{ + int T; + std::cin >> T; + for (int i = 0; i < T; ++i) + { + long long X, Y; + long long D; + double Df; + std::cin >> D; + std::cin >> X; + std::cin >> Y; + + if (!((X * X + Y * Y) % D) && is_square((X*X + Y*Y) / D)) { + std::cout << (long long)round((X*X + Y*Y) / D) << std::endl; + continue; + } + Df = sqrt(D); + long double ans = sqrt(((X * X) + (Y * Y))) / Df; + if ((long long)ceil(ans) == 1) ans = 2; + //if (ans != 0) ans -= 1e-6; + std::cout << (long long)ceil(ans) << std::endl; + } + return 0; +} \ No newline at end of file diff --git a/bapc-b-sample b/bapc-b-sample new file mode 100644 index 0000000..7c302af --- /dev/null +++ b/bapc-b-sample @@ -0,0 +1,23 @@ +1 +3 21 +1 2 +1 3 +1 3 +1 4 +1 5 +1 6 +2 3 +2 3 +2 4 +2 5 +2 6 +2 6 +3 4 +3 5 +3 5 +3 6 +4 5 +4 5 +4 6 +5 6 +5 6 diff --git a/bapc-b-sample0 b/bapc-b-sample0 new file mode 100644 index 0000000..190cedf --- /dev/null +++ b/bapc-b-sample0 @@ -0,0 +1,6 @@ +1 +2 4 +1 3 +2 4 +3 4 +1 2 diff --git a/bapc-b.cpp b/bapc-b.cpp new file mode 100644 index 0000000..bd74005 --- /dev/null +++ b/bapc-b.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +#include + +typedef std::vector< std::vector > Graph; + +int recurse(Graph &graph, bool* todo, int j, int N, std::vector &members) { + if (!todo[j]) return 0; + todo[j] = false; + members.push_back(j); + int total = 1; + for (int k = 0; k < N; k++) { + if (graph[j][k]) { + total += recurse(graph, todo, k, N, members); + } + } + return total; +} + +int main(int argc, char const *argv[]) +{ + int C; + std::cin >> C; + for (int i = 0; i < C; ++i) + { + int N, M; + std::cin >> N; + std::cin >> M; + N *= 2; + Graph graph(N, std::vector(N)); + for (int j = 0; j < N; j++) { + for(int k = 0; k < N; k++) { + graph[j][k] = (j != k); + } + } + for (int j = 0; j < M; j++) { + int A, B; + std::cin >> A; + std::cin >> B; + A--; B--; + if (A == N || B == N) { + std::cerr << "too high" << std::endl; + } + graph[A][B] = false; + graph[B][A] = false; + } + std::list groups; + std::list< std::vector > group_members; + int temp = N; + bool todo[N]; + for(int j = 0; j < N; j++) { + if (!todo[j]) continue; + group_members.emplace_back(std::vector()); + groups.push_back(recurse(graph, todo, j, N, group_members.back())); + } + + for (int c : groups) { + std::cout << "group: " << c << std::endl; + } + + /* code */ + } + return 0; +} \ No newline at end of file diff --git a/bapc-c.cpp b/bapc-c.cpp new file mode 100644 index 0000000..f64b0eb --- /dev/null +++ b/bapc-c.cpp @@ -0,0 +1,34 @@ +#include +#include + +int main(int argc, char const *argv[]) +{ + int T; + std::cin >> T; + for(int i = 0; i < T; i++) { + int C; + std::cin >> C; + char field[1000][1000]; + memset(field, 1000*1000, 0); + int xpos = 500; + int ypos = 500; + for (int j = 0; j < C; j++) { + char letter; + std::cin >> letter; + int magnitude; + std::cin >> magnitude; + switch(letter) { + case 'x': + while(magnitude--) { + field[x++][y] = 1; + } + break; + case 'y': + + case 'z': + + } + } + } + return 0; +} \ No newline at end of file diff --git a/bapc-d.cpp b/bapc-d.cpp new file mode 100644 index 0000000..89645fd --- /dev/null +++ b/bapc-d.cpp @@ -0,0 +1,65 @@ +#include +#include +#include + +#include +using std::vector; + +typedef vector > Board; + +int check_white(Board &board, std::stack< std::pair > &todo, int row, int col, int N) { + if (row >= 0 && col >= 0 && row < N && col < N) { + if (board[row][col] == '-') { + board[row][col] = 'w'; + todo.push(std::make_pair(row, col)); + return 1; + } + } + return 0; +} + +int main(int argc, char const *argv[]) +{ + int T; + std::cin >> T; + for (int i = 0; i < T; ++i) + { + int N; + std::cin >> N; + Board board(N,vector(N)); + for (int row = 0; row < N; row++) { + char temp[N+1]; + std::cin >> temp; + for(int col = 0; col < N; col++) { + board[row][col] = temp[col]; + } + } + + // fill stack with whites + std::stack< std::pair > todo; + for (int row = 0; row < N; row++) { + for (int col = 0; col < N; col++) { + if (board[row][col] == 'w') { + todo.push(std::pair(row, col)); + } + } + } + int no_made_white = 0; + while(!todo.empty()) { + std::pair n = todo.top(); + todo.pop(); + int row = n.first; + int col = n.second; + no_made_white += check_white(board, todo, row-1, col-1, N); + no_made_white += check_white(board, todo, row-1, col, N); + no_made_white += check_white(board, todo, row-1, col+1, N); + no_made_white += check_white(board, todo, row, col-1, N); + no_made_white += check_white(board, todo, row, col+1, N); + no_made_white += check_white(board, todo, row+1, col-1, N); + no_made_white += check_white(board, todo, row+1, col, N); + no_made_white += check_white(board, todo, row+1, col+1, N); + } + std::cout << no_made_white << std::endl; + } + return 0; +} diff --git a/bapc-e.cpp b/bapc-e.cpp new file mode 100644 index 0000000..0c77235 --- /dev/null +++ b/bapc-e.cpp @@ -0,0 +1,36 @@ +#include +#include +#include + + + +int main(int argc, char const *argv[]) +{ + int T; + std::cin >> T; + for (int i = 0; i < T; ++i) + { + int N; + std::cin >> N; + int minimum = 0; + int min_delta_g = 0x7FFFFFFF; + int delta_g = 0; + for(int j = 0; j < N; j++) { + int G,D; + std::cin >> G; + std::cin >> D; + delta_g += G - D; + //std::cout << "station " << j << " delta_g: " << delta_g << " minimum:" << min_delta_g << " (id: " << minimum << ")" << std::endl; + if (delta_g < min_delta_g) { + minimum = j; + min_delta_g = delta_g; + } + } + if (delta_g < 0) { + std::cout << "IMPOSSIBLE" << std::endl; + } else { + std::cout << (((minimum + 1) % N) + 1) << std::endl; + } + } + return 0; +} \ No newline at end of file diff --git a/bapc-f.cpp b/bapc-f.cpp new file mode 100644 index 0000000..6ac899d --- /dev/null +++ b/bapc-f.cpp @@ -0,0 +1,76 @@ +#include +#include +#include +#include +#include +#include + +using std::string; + +struct block { + int n; + int no_connected; + block* connected[4]; +}; + +void fill(block* b, int n) { + if (b->n != -1) return; + b->n = n; + for(int i = 0; i < b->no_connected; i++) { + fill(b->connected[i], n); + } +} + + +int main(int argc, char const *argv[]) +{ + int T; + std::cin >> T; + for (int i = 0; i < T; ++i) + { + int n,m,p,c; + std::cin >> n; + std::cin >> m; + std::cin >> p; + std::cin >> c; + block blocks[n][m]; + for(int x = 0; x < n; x++) + for(int y = 0; y < m; y++) { + blocks[x][y].n = -1; + blocks[x][y].no_connected = 0; + } + + block* powered[p]; + for(int j = 0; j < p; j++) { + int x,y; + std::cin >> x; + std::cin >> y; + powered[j] = &blocks[x][y]; + } + for(int j = 0; j < c; j++) { + int x,y; char d; + std::cin >> x; + std::cin >> y; + std::cin >> d; + if (d == 'R') { + blocks[x][y].connected[blocks[x][y].no_connected++] = &blocks[x+1][y]; + blocks[x+1][y].connected[blocks[x+1][y].no_connected++] = &blocks[x][y]; + } else { + blocks[x][y].connected[blocks[x][y].no_connected++] = &blocks[x][y+1]; + blocks[x][y+1].connected[blocks[x][y+1].no_connected++] = &blocks[x][y]; + } + } + for (int j = 0; j < p; j++) { + fill(powered[j], 0); + } + int cur_groups = 0; + for(int x = 0; x < n; x++) + for(int y = 0; y < m; y++) { + if (blocks[x][y].n == -1) { + fill(&blocks[x][y], ++cur_groups); + } + } + std::cout << cur_groups << std::endl; + } + return 0; +} \ No newline at end of file diff --git a/bapc-i.cpp b/bapc-i.cpp new file mode 100644 index 0000000..e0b191f --- /dev/null +++ b/bapc-i.cpp @@ -0,0 +1,77 @@ +#include +#include +#include +#include +#include + +using std::string; + +enum Color {B, G, R, Y}; +Color colors[] = {B, G, R, Y}; + +typedef unsigned char Value; +typedef std::pair Tile; +typedef std::set SortCounter; + + +Color to_col(char c) { + switch (c) { + case 'b': return B; + case 'g': return G; + case 'r': return R; + case 'y': return Y; + default: throw; + } +} + +void record(string token, SortCounter &counts) { + counts.emplace(Tile(to_col(token.back()), + std::stoul(token.substr(0, token.size()-1)))); +} + +bool rummisearch(SortCounter &counts) { + for (Color c : colors) { + for (Value v = 1; v <= 98; ++v) { + if (counts.count(Tile(c, v)) + && counts.count(Tile(c, v+1)) + && counts.count(Tile(c, v+2))) { + + return true; + } + } + } + for (Value v = 1; v <= 100; ++v) { + int i = 0; + for (Color c : colors) { + if (counts.count(Tile(c, v))) { + ++i; + } + if (i >= 3) return true; + } + } + return false; +} + + +int main(int argc, char const *argv[]) +{ + int T; + std::cin >> T; + for (int i = 0; i < T; ++i) + { + int M; + std::cin >> M; + SortCounter counter; + for (int j = 0; j < M; j++) { + std::string in; + std::cin >> in; + record(in, counter); + } + if (rummisearch(counter)) { + std::cout << "YES" << std::endl; + } else { + std::cout << "NO" << std::endl; + } + } + return 0; +} \ No newline at end of file diff --git a/bapc-j.cpp b/bapc-j.cpp new file mode 100644 index 0000000..2b1aa6e --- /dev/null +++ b/bapc-j.cpp @@ -0,0 +1,73 @@ +#include +#include +#include + + +bool is_impossible(int letters[], int no_chars, int leftoff) { + for (int j = 0; j < 26; j++) { + if (letters[j] > ((no_chars+1) / 2)) { + return true; + } + } + return false; +} + +int main(int argc, char const *argv[]) +{ + int T; + std::cin >> T; + for (int i = 0; i < T; ++i) + { + int letters[26]; + for(int j = 0; j < 26; j++) { + letters[j] = 0; + } + // inlezen + char c = getchar(); + int no_chars = 0; + // count + if (c == '\n') c = getchar(); + while(c != '\n') { + letters[c - 'a']++; + no_chars++; + c = getchar(); + } + + if (is_impossible(letters, no_chars, -1)) { + printf("IMPOSSIBLE\n"); + continue; + } + + char last = -1; + while(no_chars > 0) { + bool printed = false; + for (int j = 0; j < 26; j++) { + if (letters[j] > ((no_chars) / 2)) { + last = j; + letters[j]--; + putchar(j+'a'); + printed = true; + break; + } + } + if (printed) { + no_chars--; + continue; + } + for(int j = 0; j < 26; j++) { + if (letters[j] && last != j) { + last = j; + letters[j]--; + putchar(j+'a'); + break; + } + } + //printf("no more letters?!\n"); + //return -1; + no_chars--; + } + + putchar('\n'); + } + return 0; +} \ No newline at end of file diff --git a/test-x.cpp b/test-x.cpp new file mode 100644 index 0000000..891dbfc --- /dev/null +++ b/test-x.cpp @@ -0,0 +1,13 @@ +#include + +int main(int argc, char const *argv[]) +{ + unsigned int t; + std::cin >> t; + for (int i = 0; i < t; i++) { + unsigned int v; + std::cin >> v; + std::cout << (v + 1) << std::endl; + } + return 0; +} \ No newline at end of file diff --git a/test-y.cpp b/test-y.cpp new file mode 100644 index 0000000..892f561 --- /dev/null +++ b/test-y.cpp @@ -0,0 +1,16 @@ +#include +#include +#include + +int main(int argc, char const *argv[]) +{ + unsigned int t; + std::cin >> t; + for (int i = 0; i < t; i++) { + double a; + std::cin >> a; + std::cout << std::setprecision(9); + std::cout << sqrt(a / M_PI)*2.0 << std::endl; + } + return 0; +}