C - Many Requirements
已经不再是签到题了
搜索,然后check
# -*- coding: utf-8 -*-
# @time : 2023/6/2 13:30
# @file : atcoder.py
# @software : PyCharm
import bisect
import copy
import sys
from itertools import permutations
from sortedcontainers import SortedList
from collections import defaultdict, Counter, deque
from functools import lru_cache, cmp_to_key
import heapq
import math
sys.setrecursionlimit(1000)
def main():
items = sys.version.split()
if items[0] == '3.10.6':
fp = open("in.txt")
else:
fp = sys.stdin
n, m, q = map(int, fp.readline().split())
items = []
for i in range(q):
a, b, c, d = map(int, fp.readline().split())
a, b = a - 1, b - 1
items.append([a, b, c, d])
items.sort(key=lambda x: x[3], reverse=True)
p = [0] * 10
ans = 0
def check():
ret = 0
for item in items:
ai, bi, ci, di = item
if p[bi] - p[ai] == ci:
ret += di
return ret
def go(pos, cur):
nonlocal ans
if pos == n:
ans = max(ans, check())
return
p[pos] = cur
for j in range(cur, m + 1):
go(pos + 1, j)
go(0, 1)
print(ans)
if __name__ == "__main__":
main()
D Floor Function
找规律1,这个规律比较简单,打印一下易得
# -*- coding: utf-8 -*-
# @time : 2023/6/2 13:30
# @file : atcoder.py
# @software : PyCharm
import bisect
import copy
import sys
from itertools import permutations
from sortedcontainers import SortedList
from collections import defaultdict, Counter, deque
from functools import lru_cache, cmp_to_key
import heapq
import math
sys.setrecursionlimit(1000)
def main():
items = sys.version.split()
if items[0] == '3.10.6':
fp = open("in.txt")
else:
fp = sys.stdin
a, b, n = map(int, fp.readline().split())
if n >= b - 1:
x = b - 1
else:
x = n
ans = a * x // b - a * (x // b)
print(ans)
if __name__ == "__main__":
main()
E - Rotation Matching
找规律题2
一般来说,从
n
/
2
,
n
/
2
+
1
n/2,n/2+1
n/2,n/2+1开始往两边填
但是如
n
=
6
n=6
n=6的情况下,
2
,
5
2,5
2,5这一对将会发生循环
如
n
=
8
n=8
n=8的情况下,
2
,
7
3
,
6
{2,7} \ {3,6}
2,7 3,6这两对会冲突
所以遇到这种情况加1即可
# -*- coding: utf-8 -*-
# @time : 2023/6/2 13:30
# @file : atcoder.py
# @software : PyCharm
import bisect
import copy
import sys
from itertools import permutations
from sortedcontainers import SortedList
from collections import defaultdict, Counter, deque
from functools import lru_cache, cmp_to_key
import heapq
import math
sys.setrecursionlimit(1000)
def main():
items = sys.version.split()
if items[0] == '3.10.6':
fp = open("in.txt")
else:
fp = sys.stdin
n, k = map(int, fp.readline().split())
if n & 1:
i, j = 1, n
for _ in range(k):
print(i, j)
i, j = i + 1, j - 1
else:
i, j = n // 2, n // 2 + 1
for _ in range(k):
if i + n // 2 == j:
j += 1
elif i + n // 2 + 1 == j:
j += 1
print(i, j)
i, j = i - 1, j + 1
if __name__ == "__main__":
main()
F - LIS on Tree
LIS在树上的应用,模板题
注意递归前后保留上下文
// atcoder.cpp :
//
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <vector>
#include <regex>
#include <queue>
#include <climits>
using namespace std;
typedef pair<int, int> pii;
typedef long long LL;
int n;
int a[200020];
vector<int> g[200020];
int path[200020];
int ans[200020];
int l = 0;
void dfs(int u, int fa) {
int save_l = l, save_pos = -1, save = -1;
if (l == 0) {
path[l++] = a[u];
}
else {
int pos = lower_bound(path, path + l, a[u]) - path;
if (pos == l) {
path[l++] = a[u];
}
else {
save_pos = pos;
save = path[pos];
path[pos] = a[u];
}
}
ans[u] = l;
for (auto v : g[u]) {
if (v != fa) {
dfs(v, u);
}
}
l = save_l;
if (save_pos != -1) {
path[save_pos] = save;
}
}
int main()
{
//freopen("in.txt", "r", stdin);
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
for (int i = 0; i < n - 1; ++i) {
int u, v;
scanf("%d%d", &u, &v);
u--, v--;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(0, -1);
for (int i = 0; i < n; ++i)
printf("%d\n", ans[i]);
return 0;
}