update
This commit is contained in:
parent
5196d7492f
commit
46337cd1ed
3 changed files with 50 additions and 51 deletions
13
pascal.cpp
13
pascal.cpp
|
@ -11,14 +11,14 @@ int main() {
|
|||
|
||||
int N;
|
||||
cin >> N;
|
||||
if (N <= 31) {
|
||||
// if N <= 31 then just use naïve method
|
||||
if (N <= 30) {
|
||||
// if N <= 30 then just use naïve method
|
||||
for (int i = 0; i < N; ++i) cout << i + 1 << " " << 1 << '\n';
|
||||
}
|
||||
else {
|
||||
// first we try to make N - 31
|
||||
int sum = 0, side = 0, goal = N - 31;
|
||||
for (int i = 0; i < 31; ++i) {
|
||||
// first we try to make N - 30
|
||||
int sum = 0, side = 0, goal = N - 30;
|
||||
for (int i = 0; i < 30; ++i) {
|
||||
cout << i + 1 << " " << (side ? i + 1 : 1) << '\n';
|
||||
|
||||
// each row sums to 2 ^ (i + 1)
|
||||
|
@ -32,7 +32,8 @@ int main() {
|
|||
else ++sum;
|
||||
}
|
||||
|
||||
for (int i = 31; sum < N; ++i, ++sum) cout << i + 1 << ' ' << (side ? i + 1 : 1) << '\n';
|
||||
// we've undershot so we still need to walk down until our sum is N
|
||||
for (int i = 30; sum < N; ++i, ++sum) cout << i + 1 << ' ' << (side ? i + 1 : 1) << '\n';
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,7 +11,7 @@ int main() {
|
|||
|
||||
int N;
|
||||
cin >> N;
|
||||
string P[55];
|
||||
string P[55]; // patterns
|
||||
for (int i = 0; i < N; ++i) cin >> P[i];
|
||||
|
||||
string l, m, r; // left, middle, end parts of final answer
|
||||
|
@ -42,9 +42,8 @@ int main() {
|
|||
for (int j = 1; j < parts.size() - 1 && ans; ++j) m += parts[j];
|
||||
}
|
||||
|
||||
reverse(r.begin(), r.end());
|
||||
|
||||
// Creates at most ≈5000 < 10000 characters
|
||||
reverse(r.begin(), r.end());
|
||||
cout << (ans ? l + m + r : "*") << '\n';
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ typedef long long ll;
|
|||
constexpr int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
|
||||
|
||||
int S[100001]; // skill levels
|
||||
vector<int> neighbor[100001]; // vector of neighbors for each competitor
|
||||
int neighbor[100001][4]; // array of neighbors for each competitor
|
||||
|
||||
int main() {
|
||||
if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
|
||||
|
@ -19,7 +19,7 @@ int main() {
|
|||
|
||||
int R, C; cin >> R >> C;
|
||||
ll ans = 0, sum = 0;
|
||||
vector<int> check; // set of candidate competitors to check
|
||||
vector<int> check; // vector of candidate competitors to check
|
||||
for (int i = 0; i < R; ++i) {
|
||||
for (int j = 0; j < C; ++j) {
|
||||
cin >> S[i * C + j]; sum += S[i * C + j];
|
||||
|
@ -35,7 +35,6 @@ int main() {
|
|||
// precompute neighbors
|
||||
for (int i = 0; i < R; ++i) {
|
||||
for (int j = 0; j < C; ++j) {
|
||||
neighbor[i * C + j].resize(4);
|
||||
for (int d = 0; d < 4; ++d) {
|
||||
int x = i + dx[d], y = j + dy[d]; // get neighbor
|
||||
neighbor[i * C + j][d] = valid(x, y) ? x * C + y : -1;
|
||||
|
|
Loading…
Reference in a new issue