#include <iostream> using namespace std; int main() { int N, M; char ch; cin >> N >> M; for (int i = 0; i < N * M; i++) { cin >> ch; if (ch == 'C' || ch == 'M' || ch == 'Y') { cout << "#Color" << endl; return 0; } } cout<<"#Black&White"<<endl; return 0; }
#include <iostream> #include <string.h> using namespace std; int a[110000], b[110000]; long long c[110000]; bool v[110000]; int main() { int N, M, K; char ch; cin >> N >> M >> K; for (int i = 0; i < M; i++) cin >> a[i] >> b[i] >> c[i]; memset(v, false, sizeof(v)); for (int i = 0; i < K; i++) { int x; cin >> x; v[x] = true; } long long ans = 0x7FFFFFFFFFFFFFFF; for (int i = 0; i < M; i++) { if ((v[a[i]]^v[b[i]]) && c[i] < ans) ans = c[i]; } if (ans == 0x7FFFFFFFFFFFFFFF) { cout << -1 << endl; } else { cout << ans << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; int main() { long long x, a; cin >> x; if (x == 1 || x == 2) { cout << -1 << endl; return 0; } if (x % 2 == 1) { a = (x * x + 1) / 2; cout << a << ' ' << a - 1 << endl; } else { a = (x * x + 4) / 4; cout << a << ' ' << a - 2 << endl; } return 0; }
#pragma comment(linker, "/STACK:102400000,102400000") #include <stdio.h> #include <string.h> #include <vector> #include <iostream> using namespace std; vector<int> v[100005]; bool f[1005][1005]; int a[100005], b[100005], c[100005], ans[100005], sum[1005], n, m, q; void dfs(int x) { bool ac = false; if (a[x] == 1) { if ((f[b[x]][c[x]]^f[b[x]][0]) == false) { ac = true; sum[b[x]]++; ans[x]++; f[b[x]][c[x]] = !f[b[x]][c[x]]; } } else if (a[x] == 2) { if ((f[b[x]][c[x]]^f[b[x]][0]) == true) { ac = true; sum[b[x]]--; ans[x]--; f[b[x]][c[x]] = !f[b[x]][c[x]]; } } else if (a[x] == 3) { f[b[x]][0] = !f[b[x]][0]; ans[x] -= sum[b[x]]; sum[b[x]] = m - sum[b[x]]; ans[x] += sum[b[x]]; } for (int i = 0; i < v[x].size(); i++) { ans[v[x][i]] = ans[x]; dfs(v[x][i]); } if (a[x] == 1 && ac) { f[b[x]][c[x]] = !f[b[x]][c[x]]; sum[b[x]]--; } if (a[x] == 2 && ac) { f[b[x]][c[x]] = !f[b[x]][c[x]]; sum[b[x]]++; } if (a[x] == 3) { f[b[x]][0] = !f[b[x]][0]; sum[b[x]] = m - sum[b[x]]; } } int main() { scanf("%d%d%d", &n, &m, &q); for (int i = 0; i <= q; i++) { v[i].clear(); } for (int i = 1; i <= q; i++) { scanf("%d%d", &a[i], &b[i]); if (a[i] < 3) { scanf("%d", &c[i]); } if (a[i] == 4) { v[b[i]].push_back(i); } else { v[i - 1].push_back(i); } } memset(ans, 0, sizeof(ans)); memset(sum, 0, sizeof(sum)); memset(f, false, sizeof(f)); dfs(0); for (int i = 1; i <= q; i++) { printf("%d ", ans[i]); } return 0; }
#include<stdio.h> #include<iostream> #include<stdlib.h> #include<string.h> using namespace std; #define ll long long const int N = 2001; int n, m, q, p, flag[N], tb[N], cha[N]; char str[20]; ll a[N][N]; struct aa { int x, y, w; } b[N][N]; int add(int x, int y, ll z) { int j; while (x <= n) { j = y; while (j <= m) { a[x][j] += z; j += j & (-j); } x += x & (-x); } return 0; } ll sum(int x, int y) { ll s, j; s = 0; while (x > 0) { j = y; while (j > 0) { s += a[x][j]; j -= j & (-j); } x -= x & (-x); } return s; } int main(void) { //freopen("sduoj.in","r",stdin); int i, j, k, x1, x2, y1, y2; memset(flag, 0, sizeof(flag)); scanf("%d%d%d", &n, &m, &p); for (i = 1; i <= p; i++) { scanf("%d", &tb[i]); for (j = 1; j <= tb[i]; j++) { scanf("%d%d%d", &b[i][j].x, &b[i][j].y, &b[i][j].w); } cha[i] = 1; } scanf("%d", &q); while (q--) { scanf("%s", str + 1); if (str[1] == 'S') { scanf("%d", &k); cha[k] ^= 1; } else { for (i = 1; i <= p; i++)if (cha[i]) { for (j = 1; j <= tb[i]; j++) { add(b[i][j].x, b[i][j].y, b[i][j].w * ((flag[i] == 1 ? (-1) : 1))); } flag[i] ^= 1; cha[i] = 0; } scanf("%d%d%d%d", &x1, &y1, &x2, &y2); printf("%I64d ", sum(x2, y2) - sum(x1 - 1, y2) - sum(x2, y1 - 1) + sum(x1 - 1, y1 - 1)); } } return 0; }