随笔分类 - 洛谷
摘要:题目描述 某一村庄在一条路线上安装了 n 盏路灯,每盏灯的功率有大有小(即同一段时间内消耗的电量有多有少)。老张就住在这条路中间某一路灯旁,他有一项工作就是每天早上天亮时一盏一盏地关掉这些路灯。 为了给村里节省电费,老张记录下了每盏路灯的位置和功率,他每次关灯时也都是尽快地去关,但是老张不知道怎样去
阅读全文
摘要:题目背景 建筑大师最近在跟着数学大师 ljt12138 学数学,今天他学了等差数列,ljt12138 决定给他留一道练习题。 题目描述 ljt12138 首先建了 n 个特斯拉电磁塔,这些电塔排成一排,从左到右依次标号为 1到 n ,第 i个电塔的高度为 h[i]。 建筑大师需要从中选出一些电塔,然
阅读全文
摘要:传送门 思路:经典dp题,可以将第一序列离散化到第二序列,转化为最长上升子序列问题。 具体为样例 3-1 2-2 1-3 4-4 5-5,则 1 2 3 4 5 转化为 3 2 1 4 5 ,找到这个序列的最长上升子序列即为最长公共序列。 最长上升子序列 一般两种做法 1.直接枚举,枚举到第i项时,
阅读全文
摘要:题目大意,每一秒有三种选择,闪现,每次移动60m,消耗10点蓝。 跑步,每次移动17m,不耗蓝。 原地休息,回复4点蓝。 给初始蓝值,目标距离,和时间。问能达的最短时间和不能到达的最远距离。 题解:我们尽量都取闪现的方式,不够量就原地恢复,算出所能到达的最远距离。 再在每一秒比较此距离与上一秒选择跑
阅读全文
摘要:水题。。有点像蓝桥交换蚂蚁那道题。 #include<bits/stdc++.h> using namespace std; const int maxn=5500; int l,n; struct node{ int pos; int minn; int maxx; }a[maxn]; int c
阅读全文
摘要:题意是两条路径一条左上角到右下角、一条从右下角到左上角,找权值最大的两条路径。每个点只能走一次。 问题转化为和P1004方格取数一样的情形,即两条不同的路径从左上角到右下角,并去掉重复加的点即可。 #include<bits/stdc++.h> using namespace std; const
阅读全文
摘要:经典dp问题,dp[i][j][k][l],i、j代表第一个人的位置,k、l代表第二个人的位置,则列出dp方程,dp[i][j][k][l]=max(dp[i-1][j][k][l-1],dp[i-1][j][k-1][l],dp[i][j-1][k-1][l],dp[i][j-1][k][l-1]
阅读全文
摘要:还是板子。区间更新,树状数组结合差分。 #include<bits/stdc++.h> using namespace std; const int maxn=5*1e5+5; vector<int>a(maxn); vector<int>b(maxn); vector<int>v(maxn); i
阅读全文
摘要:#include<bits/stdc++.h> using namespace std; const int maxn=5*1e5+5; int tree[maxn]; int n,m,op,a,k; int lowbit(int x){ return x&(-x); } void add(int
阅读全文
摘要:https://www.luogu.com.cn/problem/P1144 #include<bits/stdc++.h> using namespace std; int n,m,A,B; int flag=0,ans=0x3f3f3f,vis[205]; int a[205]; void df
阅读全文
摘要:水题。输出的时候左对齐,宽度5,要用-5%d。 #include<bits/stdc++.h> using namespace std; int step[405][405]; int vis[405][405]; int n,m; struct node{ int x,y; node(int a,
阅读全文
摘要:djsl+优先队列求单源最短路。 #include<bits/stdc++.h> using namespace std; typedef long long int ll; const int maxn=5*1e5+5; vector<pair<ll,ll> >v[maxn]; ll dis[ma
阅读全文
摘要:https://www.luogu.com.cn/problem/P1113 给一些工作的消耗时间,和完成这些工作必须的准备工作。求完成的最少时间。 把数据建模,转化为dag,拓扑排序完事。(循环次数还是用for循环吧,用while把n减成0,debug了好久,哭了) #include<bits/s
阅读全文
摘要:一道裸的dag拓扑排序,vector模拟邻接表存出边和权值,dp数组更新最长路。 /* 展开 题目描述 设 G 为有 n 个顶点的带权有向无环图,G 中各顶点的编号为 1 到 n,请设计算法,计算图 GG 中 <1,n><1,n> 间的最长路径。 输入格式 输入的第一行有两个整数,分别代表图的点数
阅读全文
摘要:水题,图的dfs和bfs,小的优先,排下序,收获是知道vector的clear不能用来数组清零。标记数组还是用普通数组,memset清空比较妥当。 #include<bits/stdc++.h> using namespace std; int n,m,a,b; const int maxn=1e5
阅读全文
摘要:很好的题解链接,学到了懒标记和线段树的更容易写的版本。https://llkabs.blog.luogu.org/xian-duan-shu 本题主要解决区间修改,而不是单点修改。 ac代码如下 #include<bits/stdc++.h> using namespace std; typedef
阅读全文
摘要:https://www.luogu.com.cn/problem/P1434 在一个二维数组里面,找到一个依次递减的路线,求最大的那条长度 #include<iostream> #include<algorithm> #include<cstdio> #include<vector> #includ
阅读全文
摘要:https://www.luogu.com.cn/problem/P2196 给定每个点的地雷数目,再给定点能否直接到其他点的情况,求最大地雷的数目和其路径。典型dp题 如果j到i有边,有dp[i]=max(dp[i],dp[j]+a[i]); 路径存储有一个结构体,存储上一条边,最后逆序输出就好啦
阅读全文
浙公网安备 33010602011771号