#include<iostream> #include<cstdio> #include<cmath> #include<map> #define db(a) \ cout << #a << " = " << a << endl #define db2(a, b) \ cout << #a << " = " << a << " " << #b << " = " << b << endl #define inf (1<<30) #define foreach(it, m) \ for (typeof(m.begin()) it = m.begin(); it != m.end(); it++) #define MAX 2048 using namespace std; char M[MAX][MAX]; void solve(int n, int v, int h) { if (n == 1) { M[v][h] = '/'; M[v - 1][h + 1] = '/'; M[v - 1][h + 2] = '\\'; M[v][h + 1] = '_'; M[v][h + 2] = '_'; M[v][h + 3] = '\\'; } else { solve(n - 1, v, h); solve(n - 1, v - pow(2., n - 1), h + pow(2., n - 1)); solve(n - 1, v, h + pow(2., n)); } } int main() { #ifdef dennisbot freopen("in.in", "r", stdin); freopen("ou.out", "w", stdout); #endif int n; for (int i = 0; i < MAX; i++) { for (int j = 0; j < MAX; j++) { M[i][j] = ' '; } } string linea = ""; while (scanf("%d", &n) != EOF && n != 0) { for (int i = 0; i < pow(2., n + 1); i++) { for (int j = 0; j < pow(2., n + 1); j++) { M[i][j] = ' '; } } solve(n, pow(2., n) - 1, 0); for (int i = 0; i < pow(2., n) ; i++) { linea = ""; for (int j = 0; j < pow(2., n + 1); j++) { if (M[i][j] != ' ') { printf("%s%c",linea.c_str(), M[i][j]); linea = ""; } else linea += " "; } puts(""); } puts(""); } return 0; }
miércoles, 18 de abril de 2012
1406. The Sierpinski Fractal, tju online judge
Etiquetas:
1406. The Sierpinski Fractal,
judge,
online,
TJU
1178. Fractal, tju online judge
#include<iostream> #include<cstdio> #include<cmath> #include<map> #define db(a) \ cout << #a << " = " << a << endl #define db2(a, b) \ cout << #a << " = " << a << " " << #b << " = " << b << endl #define inf (1<<30) #define foreach(it, m) \ for (typeof(m.begin()) it = m.begin(); it != m.end(); it++) #define MAX 729 using namespace std; char M[MAX][MAX]; void solve(int n, int v, int h) { if (n == 1) { M[v][h] = 'X'; } else { solve(n - 1, v - pow(3., n - 2), h - pow(3., n - 2)); solve(n - 1, v - pow(3., n - 2), h + pow(3., n - 2)); solve(n - 1, v, h); solve(n - 1, v + pow(3., n - 2), h - pow(3., n - 2)); solve(n - 1, v + pow(3., n - 2), h + pow(3., n - 2)); } } int main() { #ifdef dennisbot freopen("in.in", "r", stdin); freopen("ou.out", "w", stdout); #endif int n = 7; for (int i = 0; i < MAX; i++) { for (int j = 0; j < MAX; j++) { M[i][j] = ' '; } } string linea; solve(n, (int)pow(3., n - 1) / 2, (int)pow(3., n - 1) / 2); while (scanf("%d", &n) != EOF) { if (n == -1) break; for (int i = 0; i < pow(3., n - 1) ; i++) { linea = ""; for (int j = 0; j < pow(3., n - 1); j++) { if (M[i][j] != 'X') linea += " "; else { printf("%sX", linea.c_str()); linea = ""; } } puts(""); } puts("-"); } return 0; }
martes, 17 de abril de 2012
10827 - Maximum sum on a torus, uva
#include<cstdio> #include<cstring> #include<iostream> #define db(a) cout << #a << " = " << a << endl #define db2(a, b) cout << #a << " = " << a << " " << #b << " = " << b << endl #define db3(a, b, c) cout << #a << " = " << a << " " << #b << " = " << b << " " << #c << " = " << c << endl using namespace std; int main() { #ifdef dennisbot freopen("in.in", "r", stdin); //freopen("ou.out", "w", stdout); #endif int m ,n; scanf("%d", &m); while (m --) { scanf("%d", &n); int matriz[n][n], fila[n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { scanf("%d", &matriz[i][j]); } } /*for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (j != 0) cout << " "; cout << matriz[i][j]; } cout << endl; }*/ int sum = 0, sum_min = 0,total = 0, var, max = -1000, min = 1000; for (int i = 0; i < n; i++) { memset(fila, 0, sizeof fila); for (int ii = i; ii < i + n; ii++) { sum = sum_min = total = 0; min = 1000; for (int j = 0; j < n; j++) { fila[j] += matriz[ii % n][j]; total += fila[j]; if (sum >= 0) { sum += fila[j]; } else sum = fila[j]; if (sum_min <= 0) { sum_min += fila[j]; } else sum_min = fila[j]; if (sum > max) max = sum; if (sum_min < min) min = sum_min; } max = std::max(max, total - min); } } printf("%d\n", max); } return 0; }
domingo, 8 de abril de 2012
11636 - Hello World, uva
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <vector> #include <stdio.h> #define db(a) \ cout << #a << " = " << a << endl #define db2(a, b) \ cout << #a << " = " << a << " " << #b << " = " << b << endl #define inf (1<<30) using namespace std; int lista[10001]; int main() { #ifdef dennisbot freopen("in.in", "r", stdin); #endif int seed = 1, cont = 0, t = 1; for (int i = 1; i < 10001; i++) { if (seed >= i) { lista[i] = cont; } else { while (seed *= 2, cont++, seed < i); lista[i] = cont; } } int n; while (scanf("%d", &n) != EOF && n > 0) { printf("Case %d: %d\n", t++, lista[n]); } return 0; }
domingo, 1 de abril de 2012
679 - Dropping Balls, uva
#include<iostream> #include<cstdio> #include<cstring> #include<vector> #include<utility> #define db(a) cout << #a << " = " << a << endl #define db2(a, b) cout << #a << " = " << a << " " << #b << " = " << b << endl using namespace std; int bin_to_entero(string binario) { int n = binario.size(); int t = 1, res = 0; for (int i = n - 1; i >= 0; i--) { res += t * (binario[i] - 48); t *= 2; } return res; } int main() { vector< vector<string> > level; #ifdef dennisbot freopen("in.in", "r", stdin); freopen("ou.out", "w", stdout); #endif vector<string> seed; seed.push_back("10"); seed.push_back("11"); level.push_back(seed); int t = 2; for (int k = 3; k < 21; k++) { vector<string> fila; for (int i = 0; i < t; i++) { fila.push_back(level[k - 3][i] + "0"); } for (int i = 0; i < t; i++) { fila.push_back(level[k - 3][i] + "1"); } level.push_back(fila); t *= 2; } int n, D, I; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d", &D, &I); printf("%d\n", bin_to_entero(level[D - 2][I - 1])); } scanf("%d", &n); return 0; }
785 - Grid Colouring, uva
#include<iostream> #include<cstdio> #include<cstring> #include<vector> #include<utility> #define db(a) cout << #a << " = " << a << endl #define db2(a, b) cout << #a << " = " << a << " " << #b << " = " << b << endl using namespace std; vector<string> grilla; vector< pair<int, int> > m; void dfs(char marcar,int x, int y) { if (x >= 0 && x < grilla.size() && y >= 0 && y < grilla[x].size() && grilla[x][y] == 32) { grilla[x][y] = marcar; dfs(marcar, x - 1, y); dfs(marcar, x, y - 1); dfs(marcar, x + 1, y); dfs(marcar, x, y + 1); } } int main() { #ifdef dennisbot freopen("in.in", "r", stdin); freopen("ou.out", "w", stdout); #endif int len = 0; char linea[100]; while (gets(linea) != NULL) { if (linea[0] == '_') { int n = m.size(); for (int i = 0; i < n; i++) { char marcar = grilla[m[i].first][m[i].second]; grilla[m[i].first][m[i].second] = 32; dfs(marcar, m[i].first, m[i].second); } n = grilla.size(); for (int i = 0; i < n; i++) { printf("%s\n", grilla[i].c_str()); } puts(linea); grilla.clear(); m.clear(); continue; } len = strlen(linea); for (int i = 0; i < len; i++) { if (linea[i] != 32 && linea[i] != 'X') m.push_back(make_pair(grilla.size(), i)); } grilla.push_back(linea); } return 0; }
Suscribirse a:
Entradas (Atom)