Domains
K-Dimensional Foil
Graph
Chinese Checkers
Cats and Fish
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<vector> #include<algorithm> using std::vector; using std::sort; int cmp(const void * x, const void * y) { //x < y #define datatype int return (*((datatype *)(x))) > (*((datatype *)(y))) ? 1 : -1; #undef datatype } int v[105], a[1005][105], p[1005], s[105]; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif int m, n, x; while (scanf("%d%d%d", &m, &n, &x) != EOF) { for (int i = 0; i < n; i++) scanf("%d", &v[i]); memset(a, 0, sizeof(a)); memset(p, 0, sizeof(p)); for (int i = 0; i < n; i++) s[i] = -1000000; for (int i = 0; i < n; i++) { for (int j = 0; j <= x; j += v[i]) { a[j][p[j]++] = i; } } for (int i = 0; i <= x; i++) { if (m == 0) break; if (m >= p[i]) { for (int j = 0; j < p[i]; j++) { s[a[i][j]] = i; } m -= p[i]; } else { for (int ii = 0; ii < p[i]; ii++) { for (int jj = ii + 1; jj < p[i]; jj++) { if (v[a[i][ii]] > v[a[i][jj]]) { int tmp = a[i][ii]; a[i][ii] = a[i][jj]; a[i][jj] = tmp; } } } for (int j = 0; j < m; j++) { s[a[i][j]] = i; } m = 0; } } int com = m, incom = 0; for (int i = 0; i < n; i++) { int t = x - s[i]; if (t == 0) com++; else if (t >= v[i]) continue; else incom++; } printf("%d %d ", com, incom); } return 0; }
Secret Poems
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<vector> #include<algorithm> using std::vector; using std::sort; int cmp(const void * x, const void * y) { //x < y #define datatype int return (*((datatype *)(x))) > (*((datatype *)(y))) ? 1 : -1; #undef datatype } char poem[105][105], str[10005]; const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0}; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif int n; while (scanf("%d", &n) != EOF) { for (int i = 0; i < n; i++) scanf("%s", poem[i]); int ptr = 0, dir = 1, x = 0, y = 0, p = 1; char tmp[500]; for (int i = 0; i < 2 * n - 1; i++) { int xx = x, yy = y; for (int j = 0; j < p; j++) { tmp[j] = poem[xx][yy]; xx--, yy++; } if (dir == 1) { for (int j = 0; j < p; j++) { str[ptr++] = tmp[j]; } } else { for (int j = p - 1; j >= 0; j--) { str[ptr++] = tmp[j]; } } dir *= -1; if (x + 1 < n) { x++; p++; } else { y++; p--; } } memset(poem, ' ', sizeof(poem)); for (int i = 0; i < n; i++) poem[i][n] = '