实现与例题
实现与例题
小刀刺大熊
这个作者很懒,什么都没留下…
展开
-
uva1352
#include <iostream>#include <istream>#include <sstream>#include <vector>#include <stack>#include <list>#include <map>#include <set>#include <deque>#include <queue>#include <cstring>原创 2022-03-30 22:24:48 · 539 阅读 · 0 评论 -
后缀数组板子
【代码】后缀数组板子。原创 2022-03-05 10:27:56 · 113 阅读 · 0 评论 -
字符串匹配
KMP vector<int> GetNext(string &input){ vector<int> nx(input.size() + 1,-1); int i = 0,j = -1,len = input.size(); while(i < len){ if(j == -1 || input[i] == input[j]){ nx[++i] = ++j;原创 2021-12-22 11:07:20 · 279 阅读 · 0 评论 -
最长上升子序列
dp[i] 表示包含当前元素, 0 - i 所能组成上升序列的最大长度 int lengthOfLIS(vector<int>& nums) { vector<int> dp(nums.size(),1); int res = 0; for(int i = 0;i<nums.size();++i){ for(int j = 0;j<i;++j){ if原创 2021-12-19 13:20:51 · 184 阅读 · 0 评论 -
RMQ问题(STTable)
class Log2 {public: Log2(int cnt) { lg.assign(cnt + 1, -1); for (int i = 1; i <= cnt; i++) { lg[i] = lg[i - 1] + (i & (i - 1) ? 0 : 1); } } int operator[](int len) { return lg[len]; } vector<int> lg;};Log2 lg2(maxn);class原创 2021-12-14 20:52:15 · 1551 阅读 · 0 评论 -
最短路-Floyd算法
for (int k = 0; k < n; ++k) { for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (d[i][k] < INF && d[k][j] < INF) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } } } }原创 2020-10-22 10:59:51 · 134 阅读 · 0 评论 -
最短路-Bellman-Ford算法
洛谷:p3371#include <iostream>#include <vector>#include <stack>#include <list>#include <map>#include <set>#include <deque>#include <queue>#include <cstring>#include <unordered_map>#include原创 2020-10-22 10:53:12 · 116 阅读 · 0 评论 -
最短路-Dijkstra算法
洛谷 p4779const int MAXN = 1e5+7 ,MAXM = 500007;const int INF = 0x7fffffff;struct Edge { int to, w,next; Edge() : to(0), w(0) ,next(0){}}nodes[MAXM];int heads[MAXN ] = {0}, d[MAXN] = { 0 }, visit[MAXN] = { 0 }, nCount = 0, n = 0, m = 0, s = 0;void原创 2020-10-21 19:43:18 · 95 阅读 · 0 评论 -
洛谷-P2196
int point[32], d[32][32] = { 0 }, dp[32] = {0},n, ret = -1,a = 0;vector<int> road[32];int main(){ cin >> n; for (int i = 1; i <= n; ++i) cin >> point[i]; //是有向图 i 只会指向 i+1 到 n 的节点 for (int i = 1; i < n; ++i) for (int j =原创 2020-10-10 17:42:07 · 108 阅读 · 0 评论 -
洛谷-P1434
滑雪#include <iostream>#include <vector>#include <stack>#include <list>#include <map>#include <set>#include <deque>#include <queue>#include <cstring>#include <unordered_map>#include <u原创 2020-10-09 20:14:08 · 201 阅读 · 0 评论 -
数字三角形 Number Triangles
洛谷 P1216#include <iostream>#include <vector>#include <stack>#include <list>#include <map>#include <set>#include <deque>#include <queue>#include <cstring>#include <unordered_map>#include原创 2020-10-09 19:40:22 · 102 阅读 · 0 评论 -
最近公共祖先(LCA)模板
//链式前向星const int MAXSIZE = 501000;struct Tail{ int to, next;}tail[MAXSIZE << 1];int head[MAXSIZE << 1 ] = { 0 }, f[MAXSIZE << 1 ][21] = { 0 }, dep[MAXSIZE << 1 ] = {0},tot = 0;//head数组 相当于 尾巴节点的头指针(第一个)//tail 是尾巴节点 next原创 2020-10-08 22:20:59 · 131 阅读 · 0 评论 -
P5836 [USACO19DEC]Milk Visits S
#include <iostream>#include <vector>#include <stack>#include <list>#include <map>#include <set>#include <deque>#include <queue>#include <cstring>#include <unordered_map>#include <unor原创 2020-10-07 17:47:11 · 136 阅读 · 0 评论 -
连续子数组的最大和
问题描述:求下标 0-n 的连续子数组的最大和假设数组下标:0...i...j...n0...i...j...n0...i...j...n区间[i,j][i,j][i,j]是最大和 maxsummaxsum有2种情况1.假设 maxsum<= 0; 只有一种情况,所有数都为非正数. 如果 a[x]>0a[x] >0a[x]>0,那么假设不成立。maxsum = max(maxsum,a[x]);(即找最大的负数)2.假设 maxsum>0;那么a[x] <原创 2020-10-05 19:54:03 · 1590 阅读 · 2 评论 -
字符切割
//字符分割class StrDiv{public: static CHAR * SetString(const CHAR *tString,const CHAR *tSplit); static CHAR * GetNextString(); static string inString; static CHAR* outString; st...原创 2018-05-04 16:07:15 · 431 阅读 · 0 评论 -
内存池
#ifndef __MEMORYPOOL__H__#define __MEMORYPOOL__H__#include <mutex>#define MemCount 13//#define UseMulThreadenum MemorySize{ Mem4 = 0, Mem8 = 1, Mem16 = 2, Mem32 = 3, Mem64 = 4, M...原创 2019-08-14 19:40:53 · 132 阅读 · 0 评论 -
单例类宏定义
#define DECLARINSTANCE(name) \ public:\ static name* GetInstance(){\ if(instance == nullptr){\ instance = new name;\ }\ return instance;\ }\ private:\ class GC{\ public:\ GC(){}\ .原创 2020-05-18 19:38:08 · 217 阅读 · 0 评论 -
杨辉三角求组合数
#include <vector>namespace XDC{ typedef long long ll; /*const int MOD = 1e9 + 7; const int dirX[] = {1,-1,0,0}; const int dirY[] = {0,0,1,-1};*/ //杨辉三角求组合数 class YangHuiTriangle{ private: std::vector< std::vector<ll> > angle;原创 2020-08-30 15:18:37 · 223 阅读 · 0 评论 -
最长递增序列
面试题 17.08. 马戏团人塔原题链接有个马戏团正在设计叠罗汉的表演节目,一个人要站在另一人的肩膀上。出于实际和美观的考虑,在上面的人要比下面的人矮一点且轻一点。已知马戏团每个人的身高和体重,请编写代码计算叠罗汉最多能叠几个人。示例:输入:height = [65,70,56,75,60,68] weight = [100,150,90,190,95,110]输出:6解释:从上往下数...原创 2020-03-03 12:55:57 · 225 阅读 · 0 评论 -
c++大整数运算
头文件#ifndef __BIGINT__INCLUDE__#define __BIGINT__INCLUDE__#include "XdcCommon.h"#include <vector>#include <iostream>namespace XDC{ typedef long long ll; typedef unsigned long long int ull; const int MOD = static_cast<int>(1原创 2020-09-01 17:58:26 · 1106 阅读 · 1 评论