#include<iostream> #include<cstdio> #include<cstdlib> #define db(a) cout << #a << " = " << a << endl using namespace std; string linea; int n = 0; bool esbisiesto() { bool fin = false; int num = 0, t = 1; for (int i = 0; i < 4 && !fin; i++) { if (i >= n) { fin = true; continue; } num = t * (linea[n - i - 1] - 48) + num; t *= 10; } //db(num); return (num % 4 == 0 && num % 100 != 0) or (num % 400 == 0); } int main() { bool por3, por5, por11, bisiesto, first = true; while (cin >> linea) { if (!first) puts(""); else first = false; n = linea.size(); bisiesto = esbisiesto(); int suma11 = 0; int suma3 = 0; for (int i = 0; i < n; i++) { suma3 += linea[i] - 48; if (i % 2) suma11 += linea[i] - 48; else suma11 -= linea[i] - 48; } por3 = (suma3 % 3 == 0); por5 = (linea[n - 1] - 48) % 5 == 0; por11 = suma11 % 11 == 0; if (bisiesto) puts("This is leap year."); if (por3 && por5) puts("This is huluculu festival year."); if (por5 && por11 && bisiesto) puts("This is bulukulu festival year."); if (!bisiesto && !(por3 && por5) && !(por5 && por11 && bisiesto)) puts("This is an ordinary year."); } return 0; }
viernes, 23 de diciembre de 2011
10070 - Leap Year or Not Leap Year and …, uva
Etiquetas:
10070 - Leap Year or Not Leap Year and …,
uva
jueves, 15 de diciembre de 2011
750 - 8 Queens Chess Problem , uva
#include<iostream> #include<cmath> #include<cstdio> #include<cstring> using namespace std; int x[9], a, b, cont = 0; bool place(int queen, int row) { for (int prev = 1; prev < queen; prev++) if (x[prev] == row or abs(x[prev] - row) == abs(prev - queen)) return false; return true; } void Nqueen(int queen) { if (queen == 9) { if (x[b] == a) { printf("%2d %d",++cont, x[1]); for (int i = 2; i <= 8; i++) { printf(" %d", x[i]); } puts(""); } } else { for (int row = 1; row <= 8; row++) { if (place(queen, row)) { x[queen] = row; Nqueen(queen + 1); } } } } int main() { int t; scanf("%d", &t); while (t--) { scanf("%d %d", &a, &b); memset(x, 0, sizeof x); cont = 0; printf("SOLN COLUMN\n"); printf(" # 1 2 3 4 5 6 7 8\n\n"); Nqueen(1); if (t) puts(""); } return 0; }
sábado, 10 de diciembre de 2011
11988 - Broken Keyboard (a.k.a. Beiju Text), uva
#include<iostream> #include<cstdio> #include<deque> #define db(a) cout << #a << " = " << a << endl using namespace std; deque<string> deq; void insert(bool pos, string &s) { if (pos) deq.push_back(s); else deq.push_front(s); s = ""; } int main() { string aux; bool end = true; char c; while (c = getchar()) { if (c == EOF) break; if (c == '\n') { insert(end, aux); while (deq.size()) { printf("%s", deq.front().c_str()); deq.pop_front(); } printf("\n"); deq.clear(); aux = ""; end = true; } else if (c == '[') { if (aux != "") { insert(end, aux); } end = false; } else if (c == ']') { if (aux != "") insert(end, aux); end = true; } else aux += c; } return 0; }
Etiquetas:
11988 - Broken Keyboard (a.k.a. Beiju Text),
uva
jueves, 8 de diciembre de 2011
374 - Big Mod , uva
#include<iostream> #include<ctime> #include<cstring> #include<cstdio> #define mod 131071 #define db(a) cout << #a << " = " << a << endl #define db2(a, b) cout << #a << " = " << a << " " << #b << " = " << b << endl using namespace std; int m; int power(int n, int p) { if (p == 0) return 1; if (p == 1) return n; if (p & 1) { return ((n % m) * (power(((n % m) * (n % m)) % m, (p - 1) / 2) % m)) % m; } else { return power(((n % m) * (n % m))% m, p / 2); } } int main() { int b, p; while (cin >> b >> p >> m) { cout << power(b, p) << endl; } return 0; }Click here for a great explanation
miércoles, 7 de diciembre de 2011
10176 - Ocean Deep - Make it shallow , uva
#include<iostream> #include<cstring> #include<cstdio> #define mod 131071 #define db(a) cout << #a << " = " << a << endl #define db2(a, b) cout << #a << " = " << a << " " << #b << " = " << b << endl using namespace std; int main() { string binario = "", leido; while (cin >> leido) { int len = leido.size(); if (leido[len - 1] == '#') { int res = 0; binario += leido.substr(0, len - 1); int total = binario.size(); int p = 1; for (int i = total - 1; i >= 0; i--) { res += (binario[i] - '0') * p; res %= mod; p *= 2; p %= mod; } if (res == 0) puts("YES"); else puts("NO"); binario = ""; } else binario += leido; } return 0; }
Suscribirse a:
Entradas (Atom)