AtCoder ABC165

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值