The 18th Zhejiang Provincial Collegiate Programming Contest
参考wp:https://blog.csdn.net/qq_33957603/article/details/124156811 补题链接:https://codeforces.com/gym/103055 A. League of Legends 签到题 123456789101112131415161718192021222324#include<bits/stdc++.h>using namespace std;int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long blue=0,red=0; for (int i=0;i<5;i++){ long long x; cin>>x; blue+=x; } for (int i=0;i<5;i++){ long long x; cin>>x; red+=x; } if...
数据结构-第5章—树与二叉树
树与二叉树2025/4/14树的基本概念 n个节点,n-1 条边 祖先,子孙,双亲,兄弟,堂兄弟 森林:删去根节点
线段树与树状数组
线段树参考C02【模板】线段树+懒标记 Luogu P3372 线段树 1 - 董晓 - 博客园 结构:叶子节点存储元素本身,非叶子节点存储元素统计值 遍历方式:先根遍历 节点数组tr[N*4] l, r:当前节点管理的区间范围 [l, r]。 sum:区间 [l, r] 内所有元素的和。 add:懒标记,记录未下传的区间增量。 递归建树build 初始化叶子节点(l == r)的 sum 为 w[l]。 非叶子节点递归构建左右子树,并通过 pushup 计算父节点的 sum。 区间修改change 懒标记:若当前节点区间被完全覆盖,直接更新 sum`并打标记,避免递归到底。 标记下传:在访问子节点前调用 pushdown,确保之前的修改生效。 区间查询query 若当前节点区间完全包含于查询区间,直接返回 sum。 否则下传懒标记后,递归查询左右子树并合并结果。 辅助函数 pushup:合并子节点信息到父节点。 pushdown:将懒标记下传给子节点。 模板 P3372 【模板】线段树...
数据结构-第6章—图
图2025/4/13图的基本概念定义 图不能是空图,V非空,E可以为空。 有向图: 无向图: (a,b) 完全图 有向完全图:n(n-1) 无向完全图:\frac {n*(n-1)}{2} 连通性(有向图) ,强连通性(无向图) (强)连通分量——极大(强)连通子图——尽可能包含更多的点和边 生成树 最小生成树——极小连通子图——包含必要的n-1条边 若边权相同 ,最小生成树不唯一 度 无向图:V = 2*m 有向图:V_{in} = V_{out} = m 环 n ,m>n-1 简单路径,回路 只经过一次 有向树 一个入度为0的点,其余全为入度为1的点 图的存储 邻接表 空间复杂度 O(n+e) O(n+_2e) 入度遍历所有节点 不唯一 邻接矩阵 二维数组 空间复杂度O(n^3) 压缩存储 A^n长度为n的路径数 对角线以上(下)全为0,不存在环 唯一 十字链表法 邻接多重表 图的遍历 BFS 层次遍历 非带权图的单源最短路 DFS ...
15届省赛pythonB组
[toc] A 穿越时空之门 特别要注意python整除是// 12345678910111213141516cnt = 0for i in range(1,2025): B = i cntB = 0 while B: cntB += B%2 B//=2 BB = i cntBB = 0 while BB: cntBB += BB %4 BB//=4 if cntB == cntBB: print(i) cnt+=1print(cnt) B 数字串个数 1234mod = 10**9 + 7x = (9**10000 - 2*8**10000 + 7**10000 )% modprint(x) C 连连看我的题解对一半,其余超时超时,暴力枚举对角线 12345678910111213141516171819202122232425from collections import dequen , m = map(int ,...
14届省赛pythonB组
[toc] A. 日期统计 cpp组 不小心做到cpp这组了,用python的datetime库还是挺方便的 12345678910111213141516171819202122232425262728293031str = "5 6 8 6 9 1 6 1 2 4 9 1 9 8 2 3 6 4 7 7 5 9 5 0 3 8 7 5 8 1 5 8 6 1 8 3 0 3 7 9 2 7 0 5 8 8 5 7 0 9 9 1 9 4 4 6 8 6 3 3 8 5 1 6 3 4 6 7 0 7 8 2 7 6 8 9 5 6 5 6 1 4 0 1 0 0 9 4 8 0 9 1 2 8 5 0 2 5 3 3"######print(str.replace( ,,))from datetime import timedelta,datestr1 =...
13届省赛pythonB组
[toc] A 排列字母 我的题解签到题 1234567891011121314151617import osimport syss = input()arr = [0]*100for i in range(len(s)): arr[ord(s[i]) - ord('A')] +=1for i in range(0,26): #print(arr[i],end=" ") if arr[i] != 0: for _ in range(arr[i]): print(chr(i+ord('A')),end='') 正确题解12string = 'WHERETHEREISAWILLTHEREISAWAY'print(''.join(sorted(string))) B 寻找整数 正确题解参考题解0寻找整数 - 蓝桥云课 1234567891011121314151617181920212223242526L=[]for i in...
2025_4_6 省赛集训4
[toc] A: Russian...
2025_4_6 省赛集训3
B. The Tag Game 题意大意有一颗以1为根,节点数为n的树,A在1号点,B在x号点,A,B交替行动,A的目标是行动次数尽量少,B的目标是行动次数尽量多,问在这种情况下,行动的次数. 经典学校oj过了cf过不了,我提交的只考虑了树的最大深度。 python错误解答1234567891011121314151617181920212223242526272829303132n, x = map(int,input().split()) graph = {}res = 0 def dfs(v,l): global res st[v] = True for i in graph[v]: if not st[i]: dfs(i,l+1) res = max(res, l) return for i in range(n-1): a,b = map(int,input().split()) if a not in graph: graph[a] =...