Skip to content

Instantly share code, notes, and snippets.

@aahung
Last active October 17, 2015 10:46
Show Gist options
  • Save aahung/399ac50dd99fdcc1f831 to your computer and use it in GitHub Desktop.
Save aahung/399ac50dd99fdcc1f831 to your computer and use it in GitHub Desktop.
ICPC Regionals 2012 :: Asia - Daejeon
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main() {
int case_n;
scanf("%d", &case_n);
while (case_n--) {
int v_a, v_b;
scanf("%d %d", &v_a, &v_b);
// find the sum of x + y
int sum_a = ceil(sqrt((2e0 * v_a) + 0.25) - 0.5) + 1;
int sum_b = ceil(sqrt((2e0 * v_b) + 0.25) - 0.5) + 1;
//printf("(%d %d)\n", sum_a, sum_b);
int x_a = sum_a - 1 - (sum_a * (sum_a - 1) / 2 - v_a);
int y_a = 1 + (sum_a * (sum_a - 1) / 2 - v_a);
//printf("(%d %d)\n", x_a, y_a);
int x_b = sum_b - 1 - (sum_b * (sum_b - 1) / 2 - v_b);
int y_b = 1 + (sum_b * (sum_b - 1) / 2 - v_b);
//printf("(%d %d)\n", x_b, y_b);
int x = x_a + x_b;
int y = y_a + y_b;
int sum = x + y;
int value = sum * (sum - 1) / 2 - (y - 1);
printf("%d\n", value);
}
return 0;
}
#include <stdio.h>
#include <string.h>
#define K 101
#define N 10001
char str[K][N];
int length[K];
int n;
void p() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%s", &str[i]);
length[i] = strlen(str[i]);
}
// check
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i == j) continue;
int failed = false;
int con_length = length[i] + length[j];
for (int k = 0; k < con_length; ++k) {
char a, b;
if (k < length[i]) a = str[i][k];
else a = str[j][k - length[i]];
if (con_length - 1 - k < length[i]) b = str[i][con_length - 1 - k];
else b = str[j][con_length - 1 - k - length[i]];
if (a != b) {
failed = true;
break;
}
}
if (!failed) {
printf("%s%s\n", str[i], str[j]);
return;
}
}
}
printf("0\n");
}
int main() {
int case_n;
scanf("%d", &case_n);
while (case_n--) {
p();
}
return 0;
}
#include <stdio.h>
#include <string.h>
#define N 11
#define K 31
char seq[N][K];
int length;
int out[N];
int n;
void p() {
memset(out, 0, sizeof(out));
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%s", &seq[i]);
length = strlen(seq[i]);
}
// check
for (int r = 0; r < length; ++r) {
int has_P = 0, has_R = 0, has_S = 0;
for (int i = 0; i < n; ++i) {
if (out[i]) continue;
char c = seq[i][r];
switch (c) {
case 'R':
has_R = 1;
break;
case 'P':
has_P = 1;
break;
case 'S':
has_S = 1;
break;
}
}
if ((has_P + has_R + has_S) % 2 == 1) continue;
for (int i = 0; i < n; ++i) {
char c = seq[i][r];
if (has_P == 0) {
// S out
if (c == 'S') out[i] = 1;
} else if (has_R == 0) {
if (c == 'P') out[i] = 1;
} else if (has_S == 0) {
if (c == 'R') out[i] = 1;
}
}
// check remaining robots count
int count = 0;
int who;
for (int i = 0; i < n; ++i)
if (!out[i]) {
count++;
who = i + 1;
}
if (count == 1) {
printf("%d\n", who);
return;
}
}
printf("0\n");
}
int main() {
int case_n;
scanf("%d", &case_n);
while (case_n--) {
p();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment