ICode9

精准搜索请尝试: 精确搜索
  • LeetCode/函数的独占时间2022-08-19 00:31:51

    有一个单线程CPU 正在运行一个含有 n 道函数的程序。每道函数都有一个位于 0 和 n-1 之间的唯一标识符 函数调用存储在一个调用栈 上 :当一个函数调用开始时,它的标识符将会推入栈中。而当一个函数调用结束时,它的标识符将会从栈中弹出。标识符位于栈顶的函数是 当前正在执行的函数

  • 算法提高课 第二章 搜索之DFS2022-08-18 17:00:34

    一、DFS之连通性模型 1112. 迷宫 #include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 110; int T,n; char g[N][N]; int sx,sy,ex,ey; int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1}; bool st[N][N],f; void d

  • 145.binary-tree-postorder-traversal 二叉树的后序遍历2022-08-18 11:03:33

    对比前序遍历的"中左右",后序遍历是"左右中",颠倒一下就是"中右左",所以可以参照前序遍历的迭代法来写迭代遍历。 #include <algorithm> #include <stack> #include <vector> using std::stack; using std::vector; class Solution { public: vector<int> postord

  • luogu P1721 [NOI2016] 国王饮水记2022-08-18 08:32:28

    题面传送门 首先我们发现,一定不会有低于\(h_1\)的参与操作的过程。 然后考虑一个\(x\)与比它大的\(y<z\),则发现一定是先\((x,y)\),再\((\frac{x+y}{2},z)\)更好。 因为这样是\(\frac{4}{x+y}+\frac{z}{2}\),而一起做是\(\frac{x+y+z}{3}\),显然更优。 而每个节点一定只会和一号节点联

  • 树形DP2022-08-17 21:31:49

    树形DP,顾名思义,就是在树上设计动态规划。 一般树形DP的DP数组的第一维表示节点编号,代表以此节点为根的子树作为的阶段。除此之外,可能的第二维乃至第三维与题目具体要求相关。 在树上进行动态规划时,一般先用深度优先搜索(\(DFS\))来遍历该树,定义出每个节点的深度与以该节点为根的子树

  • 递归函数处理问题类型2022-08-17 18:30:30

        #include<bits/stdc++.h> using namespace std; string read(){ string s,st; char c; int n; while(cin>>c){ if(c=='['){ cin>>n; st=read(); while(n--) s

  • *Codeforces Round #766 (Div. 2) C. Not Assigning(dfs)2022-08-16 21:33:38

    https://codeforces.com/contest/1627/problem/C 给你一个n个顶点的树,顶点从1到n,边从1到n-1。树是没有圈的连通无向图。你必须给树的每条边分配整数权重,这样得到的图就是一个素数树。 素数树是指由一条或两条边组成的每条路的重量都是素数的树。一条路径不应该访问任何顶点两次。

  • 1047.remove-all-adjacent-duplicates-in-string 删除字符串中所有相邻重复项2022-08-16 19:32:40

    利用stack(栈)这一数据结构,当前字符与栈顶字符相等时,pop(),最后把栈中的字符还原成字符串,注意栈是LIFO的,因此还原字符串时要注意顺序。 #include <stack> #include <string> using std::stack; using std::string; class Solution { public: string removeDuplicates(string

  • 20.valid-parentheses 有效的括号2022-08-16 19:30:57

    利用stack,括号匹配时pop()。 #include <stack> #include <string> using std::stack; using std::string; class Solution { public: bool isValid(string s) { stack<char> st; char temp; for (char c : s) { if (c =

  • ST表学习笔记2022-08-16 10:03:15

    简介 ST 表是用于解决可重复贡献问题(满足 \(x\) 操作 \(x=x\),如 \(max(x,x)=x\))的数据结构,它在区间查询最值时可以做到 \(O(n \log n)\) 预处理,\(O(1)\)查询,是种优秀的数据结构。 ST表 思路: ST 表基于倍增思想,我们可以先按普通的倍增想法,每次跳 \(2^i\) 步,但这样查询的复杂度是

  • LeetCode20. Valid Parentheses2022-08-15 23:34:01

    题意 序列含有'{}', '()', '[]', 判断其是否有效 方法 stack 代码 bool isValid(string s) { int N = s.size(); if (N & 1) return false; stack<char> st; for (int i = 0; i < N; i++) { if (s[i] == '('

  • 1056 组合数的和——15分2022-08-14 09:01:24

    给定N个非0的个位数字,用其中任意2个数字都可以组合成1个2位的数字。要求所有可能组合出来的2位数字的和。例如给定2、5、8,则可以组合出:25、28、52、58、82、85,它们的和为330。 输入格式: 输入在一行中先给出N(1<N<10),随后是N个不同的非0个位数字。数字间以空格分隔。 输出格式: 输出所

  • 159. Longest Substring with At Most Two Distinct Characters2022-08-14 06:30:27

    Given a string s , find the length of the longest substring t  that contains at most 2 distinct characters. Example 1: Input: "eceba" Output: 3 Explanation: tis "ece" which its length is 3. Example 2: Input: "ccaabbb" Output

  • CF1268E Happy Cactus2022-08-13 15:34:25

    题面传送门 我们先来考虑一棵树怎么做。显然先将边排序,然后从大到小加边,每次加边\((x,y)\)以后会使\(f_x=f_y=f_x+f_y\)。 但是很遗憾这个做法并不能直接搬到仙人掌上因为有些点会被算重。我们计算的是路径的数量而要求的是点的数量。 还是延续这个思路,但是当加到一个环的最后一条

  • 【牛客小白月赛】54 C School2022-08-13 02:00:36

    链接 https://ac.nowcoder.com/acm/contest/38457/C 题意是说,给你n个形如a时b分 c时d分的条件限制,表示不能选取,给出m个询问某个值是否可以选取 思路 1.可以把x时y分转化成一个值 ( x*m+y ) ,这样就可以把原条件看成n个区间的限制,用差分思想可做 点击查看代码 #include<bits/stdc++

  • 【题解】后缀自动机(SAM)选做(22.8.11)2022-08-11 19:30:38

    做完这些我才感觉我的后缀自动机入门了之前写的东西就是一坨屎 对于后缀自动机的学习,我总结了以下三句话: 千万不要死磕模板!!! 千万不要死磕模板!!! 千万不要死磕模板!!! 谁死磕模板谁&#*%#(@# 这次就主要是我对于后缀自动机的理解,只是纯纯的自动机,不包含如何构造,因为那东西实在不行就背背

  • db2笔记_3_调用存储过程2022-08-10 15:00:08

    调用存储过程 --出参 ?出参名$类型$out,后面跟入参 CALL 存储过程名(?ret$integer$out,?msg$varchar$out,'XXX',1,NULL); 创建存储过程 create or replace procedure 存储过程名( OUT o_ret int, OUT o_info VARCHAR(100), IN i_Param1 VARCHAR(100), IN i

  • [AcWing 1127] 香甜的黄油2022-08-09 01:04:54

    选一个起点,到其他点的最短距离之和最小 堆优化 dijkstra (太慢) 复杂度 \(O(n \cdot log(m) \cdot p) = 500 \times log(1450) \times 800 = 1.2 \times 10^7\) 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int,int> PII;

  • # 华为机试:HJ77火车进站 与 HJ50四则运算2022-08-08 16:31:18

    华为机试 记录两个与栈相关的算法题,折腾了一下午 需要注意dfs前后对称的操作 利用栈结构去处理存在明显先后顺序的问题,比如四则运算等 HJ77 火车进站 栈+dfs回溯 #include<bits/stdc++.h> using namespace std; int N; vector<vector<int>> res; vector<int> path; void dfs(sta

  • 质数2022-08-06 18:15:15

    相邻质数距离 https://www.acwing.com/problem/content/198/ #include <cstring> #include <iostream> #include <algorithm> using namespace std; typedef long long LL; const int N = 1000010; int primes[N], cnt; bool st[N]; void init(int n) {

  • 【数据结构】后缀表达式(输出一颗二叉表达式树的后缀表达式)2022-08-05 17:01:33

    4274. 后缀表达式 #include <iostream> #include <algorithm> #include <cstring> using namespace std; const int N = 25; int n; string v[N]; int l[N], r[N]; bool st[N]; void dfs(int u) { cout << '('; if(l[u] != -1

  • 旅行商问题模板2022-08-03 11:34:48

    题意 旅行商问题,经过每个点一次,问从原点出发走回原点的最小距离 P对NP问题是Steve Cook于1971年首次提出。“P/NP问题”,这里的P指多项式时间(Polynomial),一个复杂问题如果能在多项式时间内解决,那么它便被称为P问题,这意味着计算机可以在有限时间内完成计算;NP指非确定性多项式时间(nond

  • 【2022 杭电多校】第五场 1012 Buy Figurines 【模拟】2022-08-03 10:32:31

    链接 https://acm.hdu.edu.cn/showproblem.php?pid=7196 思路 读题后发现,由于每个人的到达时间不同,且可以唯一确定加入的队伍,所以每个人选择加入的队伍是确定的 那么只需要(按事件发生的时间顺序)模拟即可,使用优先队列 定义三元组<time,type,id> 把所有入队、出队操作看成操作序

  • [AcWing 1098] 城堡问题2022-08-02 17:33:27

    需要处理输入的 Flood Fill 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 1000 + 10; #define x first #define y second int n, m; int g[N][N]; bool st[N][N]; int dx[] = {0, -1, 0, 1}; int dy[] = {-1, 0, 1,

  • [AcWing 1097] 池塘计数2022-08-02 17:00:27

    Flood Fill 问题 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 1000 + 10; #define x first #define y second int n, m; char g[N][N]; bool st[N][N]; void bfs(int x, int y) { queue<pair<int,int>

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有