算法
幼儿园的东东小盆友
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
C. Uncle Bogdan and Country Happiness
原题连接 想法是从叶子节点出发往跟上走,然后在用bfs做。有些bug找不到了 dfs正好。 回溯的过程中统计总的人数,贪心的让每个节点的好心情的人数是正确的,然后进行条件判断,因为是从叶子节点走,所以本来的好人边坏变成了坏人变好 有这么一个数学方程式来推理好人的数目 node[i].good + node[i].sad = 总人数 node[i].good - node[i].sad = 题目的h[i] 然后两式子相加 可以推出来 node[i].good = (总人数 + 题目给的h[i]) / 2 #i原创 2020-08-05 14:33:35 · 242 阅读 · 0 评论 -
B. Captain Flint and a Long Voyage
原题链接 贪心 #include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while(t--) { int n; cin >> n; if(n == 1) { cout << 8 << endl; }else if (n == 2) {原创 2020-08-05 14:27:39 · 182 阅读 · 0 评论 -
A. Captain Flint and Crew Recruitment
原题连接 简单贪心 #include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while(t--) { int n; cin >> n; // 6 10 14 if(n <= 30) { cout << "NO" << endl;原创 2020-08-05 14:26:44 · 199 阅读 · 0 评论 -
Square
Square dfs主要是注意回溯时候的剪枝操作 #include<bits/stdc++.h> using namespace std; int n; int a[25]; int f[25]; int goal = 0; int m; int flag = false; void dfs(int n, int last, int now) { if(n == 5) { flag = true; return ; } if(now ==原创 2020-07-26 14:30:20 · 204 阅读 · 0 评论 -
Eddy‘s picture
Eddy’s picture 裸的最小生成树 #include<bits/stdc++.h> using namespace std; double x[105]; double y[105]; int root[105]; int sum = 0; double minTree = 0.0; struct node { int i; int j; double len; }edge[10005]; int f(int x) { if(x == root[x原创 2020-07-26 14:26:18 · 283 阅读 · 0 评论 -
B - Find a way
双向bfs 还是比较水的。 用vector记录下来每一个KCF 然后每次bfs都判断一个是否有哪些点是2个人都到达的点,直接输出答案就可 #include<bits/stdc++.h> using namespace std; int n, m; int Map[205][205]; int flagY[205][205]; int flagM[205][205]; int dir[4][2] = {-1, 0, 1, 0, 0, -1, 0, 1}; struct node { i原创 2020-07-17 23:25:50 · 200 阅读 · 0 评论 -
A - String Distance and Transform Process
一道朴素dp题 递推方程 还是比较好推的 路径不好找 路径的方法: 从二维数组最后一个位置往回推,可以通过到达该点的的步数判断从哪个点推过来, 判断完这个步骤以后,dp[i][j]就是a的前i个字母和b的前j个字母匹配成功了,然后4种情况输出路径就好了 #include <bits/stdc++.h> using namespace std; const int maxn = 85; int dp[maxn][maxn]; string a, b; void path() { int原创 2020-07-17 23:18:23 · 194 阅读 · 0 评论 -
LeetCode--四数之和(双指针)
四数之和 给定一个包含 n 个整数的数组 nums 和一个目标值 target,判断 nums 中是否存在四个元素 a,b,c 和 d ,使得 a + b + c + d 的值与 target 相等?找出所有满足条件且不重复的四元组。 注意: 答案中不可以包含重复的四元组。 示例: 给定数组 nums = [1, 0, -1, 0, -2, 2],和 target = 0。 满足要求的四元组集合为: [ [-1, 0, 0, 1], [-2, -1, 1, 2], [-2, 0, 0, 2] ] imp原创 2020-05-12 21:05:01 · 190 阅读 · 0 评论 -
[SCOI2005]互不侵犯
互不侵犯 展开 题目描述 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案。国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共8个格子。 注:数据有加强 输入格式 只有一行,包含两个数N,K ( 1 <=N <=9, 0 <= K <= N * N) 输出格式 所得的方案数 输入 3 2 输出 16 一道入门级别的状压DP #incl...原创 2020-04-30 11:33:10 · 355 阅读 · 0 评论 -
[BFS+位运算+状态压缩]位运算的真谛(赋c++和java代码)
原题链接 Problem Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王喜欢)…… 这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢的某些地方安装了带锁的门,钥匙藏在地牢另外的某些地方。刚开始Ignatius被关在(sx,sy)的位置,离开地牢的门在(ex,ey)的位置。Ignatius每分钟只能从一个坐标走到相邻四个坐标中的其中一个。魔...原创 2020-04-14 12:08:37 · 254 阅读 · 0 评论 -
【hdu-3461】巧用并查集+快速幂+思考
题意也有些难理解—— 给你一个锁,这个所由n个字母组成,然后这个锁有m个区间,每次可以对一个区间进行操作,并且区间中的所有字母要同时操作。每次操作可以将区间中所有字母+1。即把a变成b,把z变成a。 举个例子,比如有一个锁,由abcdef组成,前三个字母abc是一个区间,第四五个字母de是一个区间,那么如果对abc操作一次,则获得新锁bcddef,再对de区间操作一次,得bcdeff。但是,最后一...原创 2020-03-30 12:15:04 · 215 阅读 · 0 评论 -
Codeforces Round #629 (Div 3) A~D题
A 签到水体 By wdjuruo, contest: Codeforces Round #629 (Div. 3), problem: (A) Divisibility Problem, Accepted, #, Copy, hack it! #include <bits/stdc++.h> using namespace std; typedef long long ll; ...原创 2020-03-27 12:41:57 · 156 阅读 · 0 评论 -
【hdu-3938_Portal】离线并查集
Problem Description ZLGG found a magic theory that the bigger banana the bigger banana peel .This important theory can help him make a portal in our universal. Unfortunately, making a pair of portals ...原创 2020-03-19 21:43:15 · 193 阅读 · 0 评论 -
【HDU 1811 Rank of Tetris】利用并查集缩点+拓扑排序
题目: 自从Lele开发了Rating系统,他的Tetris事业更是如虎添翼,不久他遍把这个游戏推向了全球。 为了更好的符合那些爱好者的喜好,Lele又想了一个新点子:他将制作一个全球Tetris高手排行榜,定时更新,名堂要比福布斯富豪榜还响。关于如何排名,这个不用说都知道是根据Rating从高到低来排,如果两个人具有相同的Rating,那就按这几个人的RP从高到低来排。 终于,Lele要开始行动...原创 2020-03-16 16:49:52 · 169 阅读 · 0 评论 -
【Codeforces Round #624 (Div. 3)】F
原题连接 要求每一对(i,j)的最小距离的和 可以通过题目给出的那些数据列出一个线性方程 x=vit+x0; x2=vit+x0; 这就是每一个点的运动轨迹 求2个点距离的最小值 当他们的轨迹 在 t<0 的 那边时候2个点的距离的最小值就是他们初始的距离相减的绝对值 而当t>0时,2个点距离的最小值就是0 t要大于0 我们可以列出一个方程组 v1t+x1=v2t+x2 解得:t=(x...原创 2020-03-15 22:53:46 · 157 阅读 · 0 评论 -
【Codeforces 627 div(3) E】E. Sleeping Schedule
原题链接 #include<iostream> #include<algorithm> #include<string.h> using namespace std; int a[2005]; int dp[2005][2005]; //dp[i][j]表示到了第i天现在睡醒是第j小时的最大良好睡眠次数 int main()di { int n,h,l...原创 2020-03-15 16:09:03 · 198 阅读 · 0 评论 -
【并查集逆序】洛谷P1197
顺序做一定会超时 考虑逆序做 先把该删除的点全部删除 然后逆序加入图中,在加入的过程判断联通不联通; 不联通的话就让连通块的个数-1;然后把2个连通块连起来 还是比较难的 #include <bits/stdc++.h> using namespace std; const int N=4e5+5; struct node{ int f,t; int nex; }ed...原创 2020-02-29 20:58:33 · 254 阅读 · 0 评论 -
【hdu-3506四边不等式优化区间dp】Monkey Party
一遍比较好的四边不等式优化详解 #include<iostream> #include<algorithm> #include<string.h> using namespace std; const int N=1050; int a[N*2]; int dp[2*N][2*N]; int s[2*N][2*N]; int sum[2*N]; int inf=...原创 2020-02-23 22:55:24 · 149 阅读 · 0 评论 -
【线段树模板】洛谷P1198-最大数
这个就是线段树模板 #include<bits/stdc++.h> using namespace std; typedef long long ll; int mod; const int N=200000+5; struct node{ int l,r; int v=0; int id; }tree[N<<4]; int a[N]; void b...原创 2020-02-20 21:14:45 · 213 阅读 · 0 评论 -
【线段树和树状数组】洛谷P-1972HH的项链
原题链接 先是树状数组代码 在线做法应该是非常耗时的 所以这里考虑离线做法 按照每次询问的r边界进行从小到大的排序 就可以处理了 #include<bits/stdc++.h> using namespace std; const int N=1e6+5; int a[N]; int tree[N]; int flag[N]; int n; int res[N]; struct nod...原创 2020-02-20 18:54:38 · 268 阅读 · 0 评论 -
【最长下降子列和】hdu-1160
这是一段 我怎么提交都WA的 代码 #include <iostream> #include <stack> #include <algorithm> using namespace std; typedef struct{ int speed; int weight; int num; }m; bool cmp(m a,m b) {...原创 2020-02-17 16:24:59 · 127 阅读 · 0 评论 -
【区间dp】hdu4238_You Are the One
翻看了很长题解 现在还是马马虎虎 有点看不懂 先收藏到博客 慢慢理解 区间dp dp[i][j]表示从第i个人到第j个人的最小不高兴度,那么如果不管i前面的人,如果i是第k个登录舞台的人,那么i+1到i+k-1的人肯定已经登录上了舞台,那么枚举i是第k名登录舞台,这时候的dp方程就是 dp[i][j]=min(dp[i][j],dp[i][i+K-1]+dp[i+k][j]+a[i](k-1)+k...原创 2020-02-15 22:43:39 · 161 阅读 · 0 评论 -
【动态规划】hdu-1024_Max Sum Plus Plus
#include<bits/stdc++.h> using namespace std; const int N=1e6+5; int a[N]; int dp[3][N]; int n,m; //dp[i][j]表示前j个数字分成i段的最大值; //经过推导发现,dp的第i行只受到了i-1行的影响; //所以我们可以进行空间的优化 //dp[i][j]=max(dp[i-1][k]+...原创 2020-02-15 16:12:33 · 187 阅读 · 0 评论 -
【奇怪的动态规划】洛谷P-1113杂务
翻了翻题解 我被惊艳了 水一发博客 因为题目保证了杂务k(k>1)k(k>1)的准备工作只可能在杂务11至k-1k−1中。 所以到达杂务k时,前k-1个杂务一定是已经可以求出其最晚时间的 于是这就变成了一道动态规划题目,可这明摆着是拓扑排序啊 DP属实强大 题解代码:(写了对他的解释) #include<iostream> #include<cstdio> #i...原创 2020-02-13 22:09:52 · 175 阅读 · 0 评论 -
【拓扑排序--水题】洛谷P1113 杂务
原题链接 这应该是个拓扑排序的模板题,直接放代码 #include <bits/stdc++.h> using namespace std; vector<int> vec[10005]; vector<int> vec2[10005]; int t[10005]; int t2[10005]; int rudu[10005]; int flag[10005];...原创 2020-02-13 21:54:53 · 143 阅读 · 0 评论 -
【区间dp】洛谷P1063能量项链
原题链接 做个题和洛谷P1880做法类似,基本上是一个题 直接看代码注释 #include <bits/stdc++.h> using namespace std; const int N=205; int a[N]; int f[205][205]; int main() { int n; cin>>n; for(int i=1;i<=n;...原创 2020-02-13 18:27:34 · 220 阅读 · 1 评论 -
【翻看题解想不通系列之动态规划】洛谷--P1026统计单词个数
题目描述 给出一个长度不超过 200200 的由小写英文字母组成的字母串(该字串以每行 2020 个字母的方式输入,且保证每行一定为 2020 个)。要求将此字母串分成 kk 份,且每份中包含的单词个数加起来总数最大。 每份中包含的单词可以部分重叠。当选用一个单词之后,其第一个字母不能再用。例如字符串 this 中可包含 this 和 is,选用 this 之后就不能包含 th。 单词在给出的一个...原创 2020-02-13 00:19:27 · 513 阅读 · 0 评论 -
【不翻题解想不到系列,最长公共子序列】洛谷P1439
题目: 给出1-n的两个排列P1和P2,求它们的最长公共子序列。 输入格式 第一行是一个数n, 接下来两行,每行为n个数,为自然数1-n的一个排列。 输出格式 一个数,即最长公共子序列的长度 规模 1e5; 数据规模很大 n²代码 卡死你 #include<bits/stdc++.h> using namespace std; const int maxn=1e5+5; int a[...原创 2020-02-11 23:35:01 · 370 阅读 · 0 评论 -
【动态规划】洛谷P1541--乌龟琪
一个想通了就超级简单困难的动态规划 不翻题解想不到系列 #include<bits/stdc++.h> using namespace std; const int maxn=50; int fs[500]; int four[5]; int f[maxn][maxn][maxn][maxn];//动态规划方程意思:使用1号牌,2号牌,3号牌,4号牌分别为i个,j个,k个和l个时候所获...原创 2020-02-11 21:30:53 · 135 阅读 · 0 评论 -
【类似背包问题的动态规划】洛谷P1282多米诺骨牌
原题链接 2种思路 第1种: #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<algorithm> using namespace std; int n,ans=1005; int ...原创 2020-02-07 23:58:01 · 276 阅读 · 0 评论 -
【动态规划】poj_3280_Cheapest Palindrome
原题链接 想变成回文串增加或删除一个字符的作用效果相同,所以存的时候只用存下来增加和删除里面花费比较少的一项。因为不匹配时删除一个字符和增加一个字符效果相同,所以我们贪心的往字符串上添加字符就好了; 然后就是动态规划的方程了; 看代码: #include <iostream> #include <string> #include <algorithm> usin...原创 2020-02-05 16:19:02 · 173 阅读 · 0 评论 -
[最长公共子序列+滚动数组优化]Palindrome
原题链接 题目让求增添几个字符是字符串是回文字符串,回文字符串还可以是字符串与其逆序字符串相等;这种想法想下去,我们可以把字符串和他的逆序字符串放成两排;使更多的一样的字符对齐,我们就把一样的先对齐然后空位就是我们需要增添的字符的个数;这就是求原字符串和他逆序字符串的最长公共子序列然后用原长减去最长公共子序列长度就是答案; 因为数据为5000;所以要用到滚动数组进行优化; //package Pr...原创 2020-02-04 00:10:24 · 244 阅读 · 0 评论 -
[思维题]Alternative Accounts
2020 CCPC Wannafly Winter Camp Day5 #include <bits/stdc++.h> using namespace std; const int maxn=1e5+6; int a[maxn][4]={0}; int book[maxn]={0}; int last[maxn]={0}; int main() { int n,k; scanf...原创 2020-01-31 20:28:20 · 314 阅读 · 0 评论 -
[欧拉回路]无序字母对
无序字母对的题目链接 思考: 为什么路径要倒着存放; 欧拉回路中的奇度顶点必须是2个或者0个,才可以一笔画完; #include <bits/stdc++.h>//差值是6; using namespace std; int mapp[100][100]; int flag[100]; int book[100]; int book2[100][100]; stack<int&g...原创 2020-01-27 17:32:34 · 190 阅读 · 0 评论 -
[拓扑排序]POJ 1094
题目链接 因为题目问到了具体到哪一步排序完成了,或者出现了什么问题;所以每多增加一个字符串,就要重新进行一个拓扑排序,来判断这步操作是否可以得出答案; #include <bits/stdc++.h> using namespace std; vector<int> vec[30]; int rudu[30]; queue<int> que; queue<...原创 2020-01-27 00:53:04 · 150 阅读 · 0 评论 -
[二分图染色]洛谷 P1330 封锁阳光大学
题目链接 题目所给出的图 是一个无向且不联通的图;要求最小的螃蟹数,也就是求每个联通子图的最小螃蟹数,每条边只能有1个端点站螃蟹,可以跟据这个特点转化为一个二分图染色问题; 刚开始我想的是一种自认为比较正确贪心算法 贪心的把螃蟹放到度数比较大的点是对的,但是当2个点的度数相等时,这时候贪心是错误的,是不会贪心到最优情况; #include<bits/stdc++.h> //二分图,...原创 2020-01-26 17:26:58 · 179 阅读 · 0 评论 -
[并查集加最小环]洛谷第2661题
信息传递(并查集加最小环) 原题链接:https://www.luogu.com.cn/problem/P2661 根据题目画出有向图,此题保证途中只有一个环,在并查集向上找根是沿路更新最小环的长度即可; #include <bits/stdc++.h> using namespace std; const int N=2e5+5; int root[N]; int dis[N]; i...原创 2020-01-26 12:38:05 · 258 阅读 · 0 评论
分享