自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(72)
  • 收藏
  • 关注

原创 shell 模拟read键盘键入

{echo “第1个input”echo “第2个input”echo “第3个input”echo “第4个input”} | <shell命令>即可模拟<shell命令>请输入参数1:请输入参数2:请输入参数3:请输入参数4:

2021-08-24 14:28:44 951

原创 Matrix Profile介绍

本文摘译自https://towardsdatascience.com/introduction-to-matrix-profiles-5568f3375d90在时间序列分析中,通常对两件事感兴趣:异常和趋势。例如,医生检查一个心电图,是为了发现表明患者高危的异常事件。在零售行业工作的个人需要了解什么商品销售以及何时出售(季节性)以增加利润。找到时间序列内异常和趋势的一种方法是执行相似连接(similarity join)。本质上,可以通过计算每对序列片段之间的距离,将时间序列的片段与自身进行比较。尽.

2021-03-25 10:22:16 3161

原创 C语言 文件输入输出

输入:freopen(“xxx.txt”,“r”,stdin);输出:freopen(“xxx.txt”,“w”,stdout);#include<cstdio>int main(){ int n; freopen("123.txt","r",stdin); scanf("%d",&n); freopen("321.txt","w",st...

2019-09-17 08:19:28 618

原创 hdu1260 Tickets(dp/输出格式)

题目描述简单,注意构造数组和输出格式#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int k;int each[2000];int adj[2000];int dp[2000];int main(){ int N; scanf...

2019-09-16 17:11:36 237

原创 洛谷P1550 [USACO08OCT]打井Watering Hole(kruskal/并查集)

题目描述把水源看作一个点,用最小生成树做,很厉害了!#include<cstdio>#include<queue>#include<algorithm>#include<cstring>using namespace std;const int MAX=305;int n;struct edge{ int u,v,weig...

2019-07-07 23:56:41 211

原创 P2068 统计和(线段树/树状数组 简单模板题)

题目描述前两天刚学习了线段树和树状数组~于是今天拿一道基础题练练手,基本上就是套模板,最重要的是理解!线段树做法#include<cstdio>const int MAXN=100005;int n,w;int k[MAXN*2];void add(int a,int v,int l,int r,int cur){ if(l==r){ k[cu...

2019-07-04 22:13:55 203

原创 P1352 没有上司的舞会(树状dp)

题目描述了解了树状dp原理以后这道题还是很模板题的(#include<cstdio>#include<vector>#include<algorithm>using namespace std;int n;int index[6005];vector<int> son[6005];int dp[6005][2];int root[...

2019-07-04 21:16:13 542

原创 树状数组入门经典题/HDU1166/HDU1754

线段树做法传送门树状数组主要核心思想将就是,lowbit,update和getsumHDU1166:题目描述更新单点,求区间总和#include<cstdio>#define lowbit(i) ((i)&(-i))const int MAXN=50005;int c[MAXN];int T,n;void update(int x,int v){ f...

2019-07-03 20:35:51 223

原创 A1057 Stack(分块思想和树状数组 第K大)

题目描述模拟stack的push和pop,并能实时查询中位数。代码是算法笔记中的代码,可作为分块思想的模板参考。#include<cstdio>#include<stack>#include<cstring>using namespace std;const int maxn=100010;const int sqrN=316;stack&lt...

2019-07-02 22:27:42 185

原创 洛谷P1631 序列合并(最小堆)

题目描述本题的数据量很大,显然把N^2个和都放进堆里是会超时的,所以采取的是先将第一行的放入堆,然后每次将取出的数的下一个(如a1-b1取出,将a1-b2弹入),如此往复就能得到答案。我使用的是stl的优先队列,最后两个例子过得时间很慢,可能还有优化吧><(图片参考洛谷题解@xkyup_king)#include<cstdio>#include<queue&...

2019-07-02 21:15:09 373

原创 C++标准模板库(STL)之priority_queue

priority_queue又称优先队列,底层由堆来实现头文件声明#include<queue>using namespace std;1.定义priority_queue<typename> name;2.访问q.top()//访问队首,无queue的front()和back()3.其他用法q.push(x)//将x入队q.pop()//令队首元...

2019-07-01 22:37:57 251

原创 C++标准模板库(STL)之queue

queue是一个先进先出的容器头文件声明#include<queue>using namespace std;1.定义queue<typename> name;2.访问q.front()//访问队首q.back()//访问队尾3.其他用法q.push(x)//将x入队q.pop()//令队首元素出队q.empty()//检验是否为空q.siz...

2019-07-01 22:22:48 409

原创 洛谷P2085 最小函数值(priority_queue)

题目描述这道题其实直接暴力也能解决 ,用stl做思路很简单,虽然耗时会久一些。注意的点是结构体的优先级设置,效果与sort是反向的。#include<cstdio>#include<queue>using namespace std;struct node{ int A,B,C,x,s; friend bool operator <(no...

2019-07-01 22:15:22 169

原创 洛谷P1280 尼克的任务(dp)

题目描述一开始想的是,正着dp,越做发现越复杂,题意难以满足。后来看到大家都逆着做,的确简单了很多。代码思路借鉴了他人,是很好的解法。#include<cstdio>#include<vector>#include<algorithm>using namespace std;vector<int> t[10005];int dp[100...

2019-07-01 21:36:15 116

转载 洛谷P1140 相似基因

题目描述转的洛谷题解@my亦客♂ ~写的很清楚了dp[i][j]代表的是,第一个碱基序列的第i位对应到第二个碱基的第j位的最大值是多少7 AGTGATG5 GTTAG当i=2,j=1时 也就是AG对应G 这个状态可以由这三个状态更新状态更新也就是,直接匹配、第一个碱基序列加一个空格、第二个碱基序列加一个空格,这三个状态。细节问题:可以用map把碱基之间的相似度处理,也可以用数...

2019-07-01 21:19:27 164

原创 洛谷P1880 [NOI1995]石子合并(区间dp)

题目描述看到这道题的第一反应是用区间dp,可是对于如何构造环以及更简单推出dp遇到困难,最后参考了洛谷题解第一的代码,在输入时就构造存放sum的数组。主程序中适用了三重循环,在数据量小时还是适用的,不知道还有没有其他的优化算法。#include<cstdio>#include<algorithm>using namespace std;const int INF=...

2019-07-01 20:52:46 154 1

原创 洛谷P1162 填涂颜色(dfs 染色)

题目描述同种类型的题目还有P1506 拯救oibh总部#include<cstdio>using namespace std;int a[32][32],b[32][32];int dx[4]={-1,1,0,0};int dy[4]={0,0,-1,1};int n,i,j;//dfs结果:最后a为0的地方都是闭合圈内void dfs(int p,int q){ ...

2019-06-30 21:17:27 249

原创 洛谷P1141 01迷宫(dfs连通)

题目描述迷宫问题,但是数据量开的很大,不可能每次都重新查一遍,所以要做优化。优化的过程参考了网上的思路,在每一次dfs时路过的每一个点记录此次dfs的序号,由此若下次碰到点已经被标记过,则可以查询这个序号所代表的答案。#include<cstdio>#include<cstring>#include<algorithm>using namespace ...

2019-06-30 17:49:21 485

原创 洛谷P1040 加分二叉树(树状dp)

题目描述这道题还挺有意思的,题目描述是中文的还挺好理解的,做一遍这道题对于树状记忆化搜索的帮助下还挺大的#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int f[35][35];int root[35][35];int n,flag=0;long...

2019-06-30 17:22:43 146

原创 线段树入门经典题/HDU1166/HDU1754

今天学习了一下线段树最简单的单点的思想,一开始有点难懂,理解了的话就还好。这两道题本质都差不多,以后有时间可能会更其他线段树的思路分享,这里就先放题目和代码:HDU1166:题目描述更新单点,求区间总和#include<cstdio>#include<algorithm>using namespace std;const int MAXN=50005;int ...

2019-06-25 22:41:03 358

原创 poj3616 Milking Time(dp)

题目描述题意:奶牛在s~e的时间区间内产奶,农场主有m个时间段可以挤奶并且给出第i个时间段的挤奶产量,农场主每次挤完奶之后必须休息时间r之后才能工作,问农场主最多可以挤多少奶按照产奶开始时间排序,然后动态规划来做#include<cstdio>#include<algorithm>#include<cstring>using namespace st...

2019-06-23 23:30:50 95

原创 hdu2859 Phalanx(dp/最大对称子序列)

题目描述以下题意参考链接给你一个nn的字符矩阵,从中选出一个最大的子矩阵(mm)满足关于斜对角线(左下角到右上角)对称,求出这个矩阵的大小m;我们可以用dp[i][j]表示当前位置到右上角这个子矩阵所能表示对称的矩阵最大值;#include<cstdio>#include<cstring>#include<algorithm>using name...

2019-06-23 23:20:55 258

原创 hdu1078 FatMouse and Cheese(dp+dfs)

题目描述题意:一只老鼠在一个n*n的地图上吃东西,每次只能垂直或者水平走,且下次要走的格子上的食物数量必须大于当前所在格子的食物数量,每次前进不能超过k格,求老鼠所能吃到的食物数量最多是多少dp+dfs的结合,需要记住这类题型#include<cstdio>#include<cstring>#include<algorithm>using names...

2019-06-23 22:02:54 102

原创 poj3186 Treats for the Cows(区间dp)

题目链接题意:给出一个含有n个数的队列,每次只能从队头或者队尾取出一个数,将第i次取出的数乘i,求总和,求取完所有的数能得到的最大值一开始没有什么很好的思路,后来参考了网上大家的做法,是从里到外递推,用区间DP,定义dp[i][j]表示队列中区间为[i, j]所能得到的最大值,得到状态转移方程:dp[i][j] = max(dp[i + 1][j] + a[i] * (n + i - j),...

2019-06-23 21:34:13 90

原创 poj1458 Common Subsequence(dp/最长公共子序列模板)

题目描述最朴实无华的最长公共子序列#include<cstdio>#include<string.h>#include<algorithm>using namespace std;char a[1000];char b[1000];int dp[1000][1000];int main(){ int n,m; while(sc...

2019-06-23 12:44:01 82

原创 hdu1160 FatMouse's Speed(dp/最长上升子序列)

题目描述题意:求最长序列,使重量递增,速度递减思路:典型最长上升子序列#include<cstdio>#include<algorithm>#include<cstring>using namespace std;struct node{ int w,s,id;}m[1005];int dp[1005];int pre[1005]...

2019-06-23 12:00:40 113

原创 hdu1176 免费馅饼(dp)

题目链接题意:一个人初始站在5号位,一个时间可移动一格,给出馅饼掉落地点及时间,求最多接到多少馅饼。最初的代码,直接按照题意来模拟:#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int n;int p[100005][15];int dp[100...

2019-06-22 22:50:59 77

原创 hdu1114 Piggy-Bank(dp/完全背包 模板)

题目描述很简单,给出n种硬币的价值和重量,以及总硬币的重量,求总硬币的最小价值。直接套用完全背包即可。#include<cstdio>#include<algorithm>using namespace std;const int INF=0x3f3f3f3f;int v[10000];int w[10000];int dp[10000];int n,m,...

2019-06-22 21:46:47 100

原创 01背包问题/完全背包问题 滚动数组代码模板

01背包问题:有 n 件物品, 每件物品的重量为 w[i], 价值为 c[i]。现有一个容量为 V 的背包, 问如何选取物品放入背包, 使得背包内物品的总价值最大。 其中每种物品都只有1件。for(int i=0;i<c;i++){ for(int v=V;v>=w[i];v--){//逆向枚举 dp[v]=min(dp[v-w[i]]+c[i],dp[v]...

2019-06-22 21:42:07 728 1

原创 hdu1074 Doing Homework(dp/状态压缩)

题目描述题意:给出n个课程,及他们的ddl和完成所需花费的时间,若规定花费时间每超出ddl一天,分数要扣除一分,求扣除分数最少的情况思路:第一反应不是很难,但是对dp题型还不是特别熟悉,后来借鉴网上思路采用状态压缩,来列出所有可能的情况下(1是已完成0是未完成),代码也是参考的,还是有难度的,具体思路在注释中有表明#include <iostream>#include <...

2019-06-22 20:05:49 66

原创 hdu1069 Monkey and Banana(dp/最长上升子序列)

题目描述题意:给出n个箱子,及他们的长宽高,求他们叠起来的最大高度(小箱子叠在大箱子上,其两维长宽小于大箱子的两维长款)思路:一个箱子,可以有六种不同的长宽组合。将其全部列出,再根据最长上升子序列的思想求出最大高度。#include<cstdio>#include<algorithm>#include<cstring>using namespace ...

2019-06-22 19:08:25 132

转载 hdu1024(动态规划+滚动数组优化)

把一个数组分成m段,  sum(i1, j1) + sum(i2, j2) + sum(i3, j3) + ... + sum(im, jm),求使得上述和最大,ik,jk是连续的jk和ik+1可以不连续动态规划,d[i][j]表示在选取第j个数字的情况下,将前...

2019-06-22 19:08:21 479

原创 A1152 Google Recruitment(字符串)

题目描述题意:给出字符串长度,及n,求给定字符串中第一个n位素数因为对字符串操作还不够熟悉,故而代码参考点击跳转,仅供自己阅读利用char数组:#include <cstdio>using namespace std;bool is_prime(int n){ for(int i=2;i*i<=n;i++){ if(n%i==0)return false; ...

2019-06-20 23:16:44 124

原创 A1155 Heap Paths(DFS)

题目描述题意:给出一个数组,求出以他构成的完全二叉树的所有路径,并判断其为大根堆还是小根堆,或者不是堆#include<cstdio>#include<vector>using namespace std;int n;int a[1005];vector<int> path;int ifmin=1,ifmax=1;void printpath...

2019-06-20 22:41:27 85

原创 A1030 Travel Plan(最短路径/Dijkstra/模板题)

题目描述题意:N个城市,M条道路,给出M条道路的距离和花费,求从起点到终点的最短路径,若有多条最短路径,求花费最小的那条两种做法:一种,直接Dijkstra,求出花费最小的最短路径;第二种,先Dijkstra求出所有最短路径,再用DFS求出花费最小的那条1.Dijkstra:#include<cstdio>#include<cstring>#include&lt...

2019-06-19 20:16:07 304

原创 A1006 Sign In and Sign Out(简单/字符串)

题目描述题意:给每个人sign in和out的时间,求最早in和最后out的人代码参考点击跳转#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#define LL long longusing namespace std;struct P{ ...

2019-06-18 22:34:30 228

原创 A1005 Spell It Right(简单/字符串)

题目描述使用c风格,故使用char数组,最后输出英文时其实可用vector#include<cstdio>#include<cstring>using namespace std;char* a[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};char b[1...

2019-06-18 21:48:30 198

原创 A1004 Counting Leaves(简单+/广搜)

题目描述求每层的叶子数,用广搜,深搜也可BFS:#include<cstdio>#include<vector>#include<queue>using namespace std;struct node{ int layer=0; vector<int> child;}tree[105];int n,m,max...

2019-06-18 21:05:16 81

原创 A1002 A+B for Polynomials(简单/map)

题目描述题意:给出两个多项式的系数,求生成多项式的系数坑:考虑系数和为零的情况要剔除使用数组也可以做,我用的是map#include<cstdio>#include<map>using namespace std;map<int,double,greater<int> > mp;int main(){ int n,m; ...

2019-06-18 20:34:15 173

原创 A1001 A+B Format(简单/string)

题目描述/* Input:-1000000 9 Output:-999,991*/#include<cstdio>using namespace std;int a,b,c;int main(){ scanf("%d%d",&a,&b); c=a+b; if(c<0) { printf("-"); ...

2019-06-17 22:50:25 226

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除