Skip to content
Open
61 changes: 61 additions & 0 deletions 2003/S3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Author: DynamicSquid
*/

#include <stdio.h>
#include <stdlib.h>

int cmp(const void* a, const void* b) {
return *((int*)a) < *((int*)b);
}

int r, c;
char grid[25][26];

int rooms_size = 0;
int rooms[10] = { 0 };

void flood(int x, int y) {
if (x < 0 || x >= c || y < 0 || y >= r || grid[y][x] == 'I')
return;
grid[y][x] = 'I';

flood(x + 1, y);
flood(x - 1, y);
flood(x, y + 1);
flood(x, y - 1);

rooms[rooms_size]++;
}

int main() {
int flooring;
scanf("%i %i %i", &flooring, &r, &c);

for (int a = 0; a < r; ++a)
scanf("%s", grid[a]);

for (int a = 0; a < r; ++a) {
for (int b = 0; b < c; ++b) {
if (grid[a][b] == '.') {
flood(b, a);
rooms_size++;
}
}
}

qsort(rooms, rooms_size, sizeof(int), cmp);

int ans = 0;
for (int i = 0; i < rooms_size; ++i, ++ans) {
if (flooring - rooms[i] < 0)
break;

flooring -= rooms[i];
}

if (ans == 1)
printf("1 room, %i square metre(s) left over", flooring);
else
printf("%i rooms, %i square metre(s) left over", ans, flooring);
}
87 changes: 87 additions & 0 deletions 2013/S3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Author: DynamicSquid
*/

#include <iostream>
#include <vector>
using namespace std;

int T, wins = 0;

void score(vector<vector<int> > games, vector<int> points) {
if (games.empty()) {
int max = 0;
for (size_t a = 1; a < points.size(); ++a) {
if (points[a] > points[max])
max = a;
}

for (size_t a = 0; a < points.size(); ++a) {
if (a != max && points[a] == points[max])
return;
}

if (max == T - 1)
wins++;

return;
}

int t1 = games.back()[0] - 1;
int t2 = games.back()[1] - 1;
games.pop_back();

points[t1] += 3;
score(games, points);
points[t1] -= 3;

points[t2] += 3;
score(games, points);
points[t2] -= 3;

points[t1]++;
points[t2]++;
score(games, points);
points[t1]--;
points[t2]--;
}

int main() {
int G;
cin >> T >> G;

vector<vector<int> > games{
{ 1, 2 }, { 1, 3 }, { 1, 4 },
{ 2, 3 }, { 2, 4 },
{ 3, 4 }
};

vector<int> points{ 0, 0, 0, 0 };

for (int a = 0; a < G; ++a) {
int t1, t2, s1, s2;
cin >> t1 >> t2 >> s1 >> s2;

for (size_t b = 0; b < games.size(); ++b) {
if ((games[b][0] == t1 && games[b][1] == t2) || (games[b][0] == t2 && games[b][1] == t1)) {
games.erase(games.begin() + b);
break;
}
}

if (s1 > s2) {
points[t1 - 1] += 3;
}
else if (s1 < s2) {
points[t2 - 1] += 3;
}
else {
points[t1 - 1]++;
points[t2 - 1]++;
}
}

score(games, points);

cout << wins;
}
31 changes: 31 additions & 0 deletions 2016/J3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Author: DynamicSquid
*/

#include <iostream>
using namespace std;

bool palindrome(string& S) {
for (int a = 0; a < (int)S.length() / 2; ++a) {
if (S[a] != S[S.length() - a - 1])
return false;
}

return true;
}

int main() {
string S;
cin >> S;

int longest = 1;
for (int a = 2; a <= (int)S.length(); ++a) {
for (int b = 0; b <= (int)S.length() - a; ++b) {
string sub = S.substr(b, a);
if (palindrome(sub) && (int)sub.length() > longest)
longest = sub.length();
}
}

cout << longest;
}
36 changes: 36 additions & 0 deletions 2017/J4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Author: DynamicSquid
*/

#include <iostream>
using namespace std;

int main() {
int D;
cin >> D;

int repeat = D / 1440;
D %= 1440;

int t = 1200, ans = 0;
for (int a = 0; a < D; ++a) {
t++;

if (t % 100 == 60)
t = (t + 100) / 100 * 100;
if (t / 100 == 13)
t = (t % 100) + 100;

int d1 = t % 10;
int d2 = (t / 10) % 10;
int d3 = (t / 100) % 10;
int d4 = t / 1000;

if (d4 != 0 && d4 - d3 == d3 - d2 && d3 - d2 == d2 - d1)
ans++;
else if (d4 == 0 && d3 - d2 == d2 - d1)
ans++;
}

cout << ans + (repeat * 62);
}
65 changes: 65 additions & 0 deletions 2018/J5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Author: DynamicSquid
*/

#include <iostream>
#include <vector>
#include <queue>
using namespace std;

vector<int> nums[10005];
bool reach[10005] = { true, false };

void can_reach(int i) {
for (int num : nums[i]) {
if (reach[num])
continue;

reach[num] = true;
can_reach(num);
}
}

int main() {
int N;
cin >> N;

for (int a = 0; a < N; ++a) {
int M;
cin >> M;

nums[a].resize(M);
for (int b = 0; b < M; ++b) {
int num;
cin >> num;
nums[a][b] = num - 1;
}
}

can_reach(0);

bool reachable = true;
for (int a = 0; a < N && reachable; ++a) {
if (!reach[a])
reachable = false;
}

cout << (reachable ? 'Y' : 'N') << '\n';

queue<vector<int> > q;
q.push({ 0, 1 });

while (!q.empty()) {
int i = q.front()[0];
int s = q.front()[1];
q.pop();

if (nums[i].empty()) {
cout << s;
break;
}

for (int num : nums[i])
q.push({ num, s + 1 });
}
}
36 changes: 36 additions & 0 deletions 2019/J3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Author: DynamicSquid
*/

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
int num;
cin >> num;

vector<string> lines(num);
for (int a = 0; a < num; ++a)
cin >> lines[a];

for (size_t a = 0; a < lines.size(); ++a) {
char letter = lines[a][0];
int count = 0;

for (size_t b = 0; b < lines[a].length(); ++b) {
if (lines[a][b] == letter) {
count++;
}
else {
cout << count << ' ' << letter << ' ';

letter = lines[a][b];
count = 1;
}
}

cout << count << ' ' << letter << '\n';
}
}
41 changes: 41 additions & 0 deletions 2020/J3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Author: DynamicSquid
*/

#include <iostream>
using namespace std;

int main() {
int N;
cin >> N;

int right = 0, left = 0, top = 0, bottom = 0;

for (int a = 0; a < N; ++a) {
int inX, inY;
cin >> inX;
cin.ignore(1);
cin >> inY;

if (a == 0) {
right = inX + 1;
left = inX - 1;
top = inY + 1;
bottom = inY - 1;
}
else {
if (inX <= left)
left = inX - 1;
else if (inX >= right)
right = inX + 1;

if (inY >= top)
top = inY + 1;
else if (inY <= bottom)
bottom = inY - 1;
}
}

cout << left << "," << bottom << "\n";
cout << right << "," << top;
}
Loading