aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTa180m2020-05-11 21:01:15 -0500
committerGitHub2020-05-11 21:01:15 -0500
commit6760ebf14ea39ff9dec78b6958b0de80e102d339 (patch)
treee7978e174887d6c7072c662518a97fe37f321188
Add files via upload
-rw-r--r--pascal.cpp43
-rw-r--r--pattern.cpp41
-rw-r--r--square.cpp77
3 files changed, 161 insertions, 0 deletions
diff --git a/pascal.cpp b/pascal.cpp
new file mode 100644
index 0000000..fd3b99d
--- /dev/null
+++ b/pascal.cpp
@@ -0,0 +1,43 @@
+#include <bits/stdc++.h>
+using namespace std;
+
+int main() {
+ if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
+
+ int T;
+ cin >> T;
+ for (int t = 0; t < T; ++t) {
+ int N;
+ cin >> N;
+ cout << "Case #" << t + 1 << ":\n";
+ if (N <= 500) {
+ for (int i = 0; i < N; ++i) cout << i + 1 << " " << 1 << '\n';
+ }
+ else {
+ N -= 32;
+ int sum = 0;
+ bool side = 0;
+ for (int i = 0; i < 32; ++i) {
+ cout << i + 1 << " " << (side ? i + 1 : 1) << '\n';
+ if (N & (1 << i)) {
+ if (side) {
+ for (int j = i; j > 0; --j) cout << i + 1 << " " << j << '\n';
+ side = 0;
+ }
+ else {
+ for (int j = 2; j <= i + 1; ++j) cout << i + 1 << " " << j << '\n';
+ side = 1;
+ }
+ sum += (1 << i);
+ }
+ else ++sum;
+ }
+ int x = 32;
+ N += 32;
+ while (sum < N) {
+ cout << x + 1 << ' ' << (side ? x + 1 : 1) << '\n';
+ ++x, ++sum;
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/pattern.cpp b/pattern.cpp
new file mode 100644
index 0000000..192c691
--- /dev/null
+++ b/pattern.cpp
@@ -0,0 +1,41 @@
+#include <bits/stdc++.h>
+using namespace std;
+
+int main() {
+ if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
+
+ int T;
+ cin >> T;
+ for (int t = 0; t < T; ++t) {
+ int N;
+ cin >> N;
+ string P[55];
+ for (int i = 0; i < N; ++i) cin >> P[i];
+
+ string a, b, c;
+ bool found = 1;
+ for (int i = 0; i < N && found; ++i) {
+ vector<string> v;
+ v.push_back("");
+ for (auto& c : P[i]) {
+ if (c == '*') v.push_back("");
+ else v.back() += c;
+ }
+ for (int j = 0; j < v.front().size() && found; ++j) {
+ if (j >= a.size()) a.push_back(v.front()[j]);
+ else if (v.front()[j] != a[j]) found = 0;
+ }
+ reverse(v.back().begin(), v.back().end());
+ for (int j = 0; j < v.back().size() && found; ++j) {
+ if (j >= c.size()) c.push_back(v.back()[j]);
+ else if (v.back()[j] != c[j]) found = 0;
+ }
+ for (int j = 1; j < v.size() - 1; ++j) b += v[j];
+ }
+ reverse(c.begin(), c.end());
+
+ cout << "Case #" << t + 1 << ": ";
+ if (found) cout << a << b << c << '\n';
+ else cout << "*\n";
+ }
+} \ No newline at end of file
diff --git a/square.cpp b/square.cpp
new file mode 100644
index 0000000..bc63ef1
--- /dev/null
+++ b/square.cpp
@@ -0,0 +1,77 @@
+#include <bits/stdc++.h>
+using namespace std;
+typedef long long ll;
+
+int main() {
+ if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
+
+ int T;
+ cin >> T;
+ for (int t = 0; t < T; ++t) {
+ int R, C;
+ cin >> R >> C;
+ cout << "Case #" << t + 1 << ": ";
+
+ vector<vector<int>> S(R);
+ set<pair<int, int>> check;
+ vector<set<int>> rs(R), cs(C);
+ ll ans = 0, sum = 0;
+ for (int i = 0; i < R; ++i) {
+ S[i].resize(C);
+ for (int j = 0; j < C; ++j) {
+ cin >> S[i][j];
+ check.emplace(i, j);
+ sum += S[i][j];
+ }
+ }
+
+ for (int i = 0; i < R; ++i) {
+ for (int j = 0; j < C; ++j) rs[i].insert(j);
+ }
+ for (int j = 0; j < C; ++j) {
+ for (int i = 0; i < R; ++i) cs[j].insert(i);
+ }
+
+ while (1) {
+ vector<pair<int, int>> elim;
+ for (auto& x : check) {
+ int i = x.first, j = x.second;
+ if (S[i][j]) {
+ int cnt = 0, num = 0;
+ auto r = cs[j].find(i);
+ if (r != cs[j].end()) {
+ if (r != cs[j].begin()) cnt += S[*(--r)][j], ++num, ++r;
+ if (r != --cs[j].end()) cnt += S[*(++r)][j], ++num;
+ }
+ auto c = rs[i].find(j);
+ if (c != rs[i].end()) {
+ if (c != rs[i].begin()) cnt += S[i][*(--c)], ++num, ++c;
+ if (c != --rs[i].end()) cnt += S[i][*(++c)], ++num;
+ }
+ if (num * S[i][j] < cnt) elim.emplace_back(i, j);
+ }
+ }
+ check.clear();
+ ans += sum;
+ for (auto& x : elim) {
+ int i = x.first, j = x.second, cnt = 0, num = 0;
+ sum -= S[i][j];
+ S[i][j] = 0;
+ auto r = cs[j].find(i);
+ if (r != cs[j].end()) {
+ if (r != cs[j].begin()) check.emplace(*(--r), j), ++r;
+ if (r != --cs[j].end()) check.emplace(*(++r), j);
+ }
+ auto c = rs[i].find(j);
+ if (c != rs[i].end()) {
+ if (c != rs[i].begin()) check.emplace(i, *(--c)), ++c;
+ if (c != --rs[i].end()) check.emplace(i, *(++c));
+ }
+ rs[i].erase(j);
+ cs[j].erase(i);
+ }
+ if (elim.empty()) break;
+ }
+ cout << ans << '\n';
+ }
+} \ No newline at end of file