**1. Public NOIP Round #1 (Div. 1, 提高 2022-09-10 14:00:00)
点击查看代码
#include <stdio.h>
#include <string.h>
char map[1000][1000];
int main() {
int T, a, b, c;
scanf("%d", &T);
while(T --) {
scanf("%d%d%d", &a, &b, &c);
for(int i = 0; i < ((b + c) << 1 | 1); i ++)
for(int j = 0; j < ((a + b) << 1 | 1); j ++) map[i][j] = '.';
for(int i = 0; i < (b << 1); i ++) {
if(i & 1) {
for(int j = 0; j < (a << 1 | 1); j += 2) map[i][(b << 1) - i + j] = '/';
for(int j = 1; j < (a << 1 | 1); j += 2) map[i][(b << 1) - i + j] = '.';
for(int j = 0; j < (c << 1); j ++)
map[i + 1 + j][((a + b) << 1) - i] = j & 1 ? '/' : '.';
} else {
for(int j = 0; j < (a << 1 | 1); j += 2) map[i][(b << 1) - i + j] = '+';
for(int j = 1; j < (a << 1 | 1); j += 2) map[i][(b << 1) - i + j] = '-';
for(int j = 0; j < (c << 1); j ++)
map[i + 1 + j][((a + b) << 1) - i] = j & 1 ? '+' : '|';
}
}
for(int i = 0; i < (c << 1); i ++)
if(i & 1) {
for(int j = 0; j < (a << 1 | 1); j += 2) map[i + (b << 1)][j] = '|';
for(int j = 1; j < (a << 1 | 1); j += 2) map[i + (b << 1)][j] = '.';
} else {
for(int j = 0; j < (a << 1 | 1); j += 2) map[i + (b << 1)][j] = '+';
for(int j = 1; j < (a << 1 | 1); j += 2) map[i + (b << 1)][j] = '-';
}
for(int j = 0; j < (a << 1 | 1); j += 2) map[(b + c) << 1][j] = '+';
for(int j = 1; j < (a << 1 | 1); j += 2) map[(b + c) << 1][j] = '-';
for(int i = 0; i < ((b + c) << 1 | 1); i ++, putchar(10))
for(int j = 0; j < ((a + b) << 1 | 1); j ++) putchar(map[i][j]);
}
return 0;
}
先选所有横坐标相同的最左边或最右边
从(纵坐标)外往内枚举,如果个数>2则将纵坐标在中间的往横坐标移动
点击查看代码
#include <set>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <algorithm>
const int N = 1e6 + 5;
typedef std::pair<int, int> PII;
int n;
struct P { int x, y, id; } a[N];
std::set<PII> set[N];
bool used[N];
std::vector<PII> rem;
int main() {
scanf("%d", &n);
for(int i = 0; i < n; i ++) scanf("%d%d", &a[i].x, &a[i].y), a[i].id = i;
std::sort(a, a + n, [](const P &x, const P &y) { return x.x < y.x || (x.x == y.x && x.y < y.y); });
for(int i = 0; i < n; i ++)
if((!i || a[i].x != a[i - 1].x) || (a[i].x != a[i + 1].x))
set[a[i].y].insert({a[i].x, i});
for(int t = 0; t < 4; t ++) {
for(int i = 1; i <= 1000000; i ++)
if(set[i].size() > 2U) {
for(auto it = ++ set[i].begin(), ed = -- set[i].end(); it != ed; it ++) {
int id = it->second;
if(a[id + 1].x == a[id].x)
set[a[id + 1].y].insert({a[id + 1].x, id + 1}), rem.push_back(*it);
}
while(rem.size()) set[i].erase(rem.back()), rem.pop_back();
}
for(int i = 1000000; i; i --)
if(set[i].size() > 2U) {
for(auto it = ++ set[i].begin(), ed = -- set[i].end(); it != ed; it ++) {
int id = it->second;
if(id && a[id - 1].x == a[id].x)
set[a[id - 1].y].insert({a[id - 1].x, id - 1}), rem.push_back(*it);
}
while(rem.size()) set[i].erase(rem.back()), rem.pop_back();
}
}
for(int i = 1; i <= 1000000; i ++)
if(set[i].size()) used[a[set[i].begin()->second].id] = used[a[set[i].rbegin()->second].id] = true;
for(int i = 0; i < n; i ++) printf("%d", int(used[i]));
putchar(10);
return 0;
}
- Public NOIP Round #2 (Div. 1, 提高 2022-10-04 08:30:00)
https://pjudge.ac/submission/52577
点击查看代码
#include <stdio.h>
#include <string.h>
#include <algorithm>
const int N = 5e5 + 5;
int n, ord[N], nxt[N], a[N], tr[N << 2];
inline int ls(int u) { return u << 1; }
inline int rs(int u) { return u << 1 | 1; }
void modify(int u, int l, int r, int x, int y) {
if(l == r) tr[u] = std::max(tr[u], y);
else {
int mid = (l + r) >> 1;
if(x <= mid) modify(ls(u), l, mid, x, y);
else modify(rs(u), mid + 1, r, x, y);
tr[u] = std::max(tr[ls(u)], tr[rs(u)]);
}
}
int query(int u, int l, int r, int x, int y) {
if(x <= l && r <= y) return tr[u];
int mid = (l + r) >> 1, res = 0;
if(x <= mid) res = std::max(res, query(ls(u), l, mid, x, y));
if(y > mid) res = std::max(res, query(rs(u), mid + 1, r, x, y));
return res;
}
int stk[N], top, res;
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; i ++) scanf("%d", a + i), ord[a[i]] = i;
stk[top = 0] = n + 1, nxt[n + 1] = n;
for(int i = n; i; i --) {
while(top && a[i] > a[stk[top]]) top --;
nxt[i] = stk[top], stk[++ top] = i;
}
for(int i = n; i; i --)
modify(1, 1, n, ord[i], query(1, 1, n, ord[i], nxt[nxt[ord[i]]] - 1) + 1);
printf("%d\n", query(1, 1, n, 1, nxt[1]));
return 0;
}