#include<iostream> #include<cstdio> #include<algorithm> #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 #define MAX 50001 using namespace std; int P[MAX], mejor[MAX]; int find(int i) { return P[i] == -1 ? i : P[i] = find(P[i]); } void join(int i, int j) { if (find(i) != find(j)) P[find(i)] = find(j);} void init(int n) { fill(P, P + n, -1);} int main() { int n, m, a, b, cont = 1; while (scanf("%d %d", &n, &m) != EOF && (n || m)) { init(n + 1); for (int i = 0; i < m; i++) { scanf("%d %d", &a, &b); join(a, b); } int res = 0; for (int i = 1; i < n + 1; i++) res += find(i) == i; printf("Case %d: %d\n",cont++ , res); } return 0; }
jueves, 24 de noviembre de 2011
10583 - Ubiquitous Religions, uva
10608 - Friends, uva
#include<iostream> #include<cstdio> #include<algorithm> #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 #define MAX 30001 using namespace std; int P[MAX], mejor[MAX]; int find(int i) { return P[i] == -1 ? i : P[i] = find(P[i]); } void join(int i, int j) { if (find(i) != find(j)) P[find(i)] = find(j);} void init(int n) { fill(P, P + n, -1);} int main() { int n, m, a, b, t; scanf("%d", &t); while (t--) { scanf("%d %d", &n, &m); init(n + 1); for (int i = 0; i < m; i++) { scanf("%d %d", &a, &b); join(a, b); } fill(mejor, mejor + n + 1, 0); for (int i = 1; i < n + 1; i++) mejor[find(i)]++; int res = *max_element(mejor, mejor + n + 1); printf("%d\n", res); } return 0; }
viernes, 18 de noviembre de 2011
10360 - Rat Attack, uva
#include<iostream> #include<cstring> #include<vector> #include<utility> #define db(a) cout << #a << " = " << a << endl #define db2(a, b) cout << #a << " = " << a << " " << #b << " = " << b << endl int killed[1025][1025]; using namespace std; int main() { int s, d, n, x, y, tam; cin >> s; for (int i = 0; i < s; i++) { memset(killed, 0, sizeof killed); cin >> d >> n; for (int j = 0; j < n; j++) { cin >> x >> y >> tam; for (int u = x - d; u <= x + d; u++) for (int v = y - d; v <= y + d; v++) { if (u >= 0 && u <= 1024 && v >= 0 && v <= 1024) killed[u][v] += tam; } } int maxi = 0; for (int u = 0; u <= 1024; u++) for (int v = 0; v <= 1024; v++) { if (maxi < killed[u][v]) { maxi = killed[u][v]; x = u; y = v; } } cout << x << " " << y << " " << maxi << endl; } return 0; }
10903 - Rock-Paper-Scissors Tournament, uva
#include<iostream> #include<iostream> #include<cstdio> #include<sstream> #include<algorithm> #include<cmath> #include<vector> #include<numeric> #include<cstring> #define db(a) cout << #a << " = " << a << endl #define db2(a, b) cout << #a << " = " << a << " " << #b << " = " << b << endl using namespace std; struct player { int win, lose; player(int win = 0, int lose = 0) : win(win), lose(lose) {} }; int main() { int p1, p2, n, k; string m1, m2; char linea[100]; stringstream ss; bool first = true; while (scanf("%d %d\n",&n , &k) == 2){ if (n == 0) break; if (!first) printf("\n"); else first = false; player jugadores[n]; int times = k * n * (n - 1) / 2; for (; times-- ; ) { gets(linea); ss.clear(); ss << linea; ss >> p1 >> m1 >> p2 >> m2; if ( m1[0] == 'r') { if (m2[0] == 's') jugadores[p1 - 1].win++, jugadores[p2 - 1].lose++; else if (m2[0] == 'p') jugadores[p1 - 1].lose++, jugadores[p2 - 1].win++; continue; } if ( m1[0] == 's') { if (m2[0] == 'p') jugadores[p1 - 1].win++, jugadores[p2 - 1].lose++; else if (m2[0] == 'r') jugadores[p1 - 1].lose++, jugadores[p2 - 1].win++; continue; } if ( m1[0] == 'p') { if (m2[0] == 'r') jugadores[p1 - 1].win++, jugadores[p2 - 1].lose++; else if (m2[0] == 's') jugadores[p1 - 1].lose++, jugadores[p2 - 1].win++; continue; } } for (int i = 0;i < n; i++) { if (jugadores[i].win + jugadores[i].lose == 0) puts("-"); else printf("%.3f\n", (double)jugadores[i].win / (jugadores[i].win + jugadores[i].lose)); } } return 0; }
Etiquetas:
10903 - Rock-Paper-Scissors Tournament,
uva
Suscribirse a:
Entradas (Atom)