
acm
Giggle1929
这个作者很懒,什么都没留下…
展开
-
第一天PAT-A1053 Path of Equal Weight
A1053description:给一个非空树,其根为Ri,以及对于每个叶子节点Ti的权重Wi。一条由R到L的路径的权重为在该路上的所有叶子节点的权重之和。现给定一个带权重的树,求所有权重为给定数字的路线。例如下图:对于每个节点,上方数字是其节点ID(2位数字),下方数字是该节点的权重。假设给定的数字是24,则存在4条不同的路线符合题意, {10 5 2 7},{10 4 10},{10 3 3 6 2} 和 {10 3 3 6 2},对应图中红色路径。Input:每个测试一个样例第一行:一棵原创 2020-08-15 21:53:02 · 123 阅读 · 0 评论 -
第一天PAT-A1020 Tree Traversals
A1020Description:假设二叉树中的key都是不同的正整数,给出后序和中序遍历序列,求这棵树的层次遍历序列Input:一个测试一组样例首行正整数N<=30,代表二叉树中所有的数字节点个数第二行给出后序序列,第三行给出中序序列72 3 1 5 7 6 41 2 3 4 5 6 7Output:对于每个测试样例,输出一行层次遍历序列,数字由空格隔开4 1 6 3 5 7 2算法构思:关键是根据后序序列(左右根)和中序序列(左根右)特性构建二叉树,代码原创 2020-08-15 20:14:43 · 112 阅读 · 0 评论 -
JSK-布设光钎-Kruscal最小生成树-并查集-图的连通性
题目链接(舍友走了四个,还剩我和老王)水题,AC如下#include<bits/stdc++.h>using namespace std;const int inf = 0x3f3f3f3f;const int maxn = 105;int n, ans, fa[maxn], cnt;struct edge{ int u, v, w; edge(int _u,...原创 2019-07-12 21:51:58 · 115 阅读 · 0 评论 -
计蒜客-连线问题-Krucal-并查集
题目链接无坑,AC代码#include<bits/stdc++.h>using namespace std;const int maxn = 105;const int inf = 0x3f3f3f3f;struct point{ int x, y; point(){ } point(int xx, int yy){ x = xx; y = yy; }...原创 2019-07-12 22:23:45 · 129 阅读 · 0 评论 -
计蒜客-穿越雷区-Kruscal最小生成树
题目链接水题做多了有害身体健康?AC代码#include<bits/stdc++.h>using namespace std;const int maxn = 30005;const int maxm = 50005;int n, m, fa[maxn], ans, cnt;struct edge{ int u, v, w; edge(int uu, int v...原创 2019-07-12 22:55:07 · 137 阅读 · 0 评论 -
计蒜客-子树的结点个数-图的遍历-深度优先搜寻
题目链接树是一种特殊的图,采用邻接表存储树结构简单的深搜,AC代码#include<bits/stdc++.h>using namespace std;const int maxn = 1005;struct edge{ int v, next;}e[maxn];int n, p[maxn], eid, tab[maxn];void init(){ memse...原创 2019-07-13 08:52:33 · 187 阅读 · 0 评论 -
计蒜客-蒜头君回家-bfs
题目链接bfs广搜,从S到P+从T到P的所有求最小值输出就好,需要注意的地方采用了STL的map,map默认按key值排序,故当使用自定义结构体时,应当在结构体内重构比较运算符,一开始只是简单比较了point的x值,后来插入有误,检查后发现当x值相等时便覆盖了相同x值的映射采用的point结构体的cnt值变化后,作为映射的key值也会变化AC代码如下:#include<bits...原创 2019-07-09 23:24:14 · 456 阅读 · 0 评论 -
计蒜客-高速公路-Kruscal-最小生成树
题目链接由于:最小生成树中的最大边一定是所有生成树中最小的故:枚举每个边, 对于每个边,以其为生成树的最小边Kruscal做生成树,求出该生成树的极差并更新AC代码#include<bits/stdc++.h>using namespace std;const int maxn = 105;const int maxm = 5000;int n, m, fa[max...原创 2019-07-14 12:45:01 · 704 阅读 · 0 评论 -
计蒜客-修建大桥-并查集做法-图的连通性
题目链接又是等前女友回消息的一天大概是要用最少的边构建一个无向连通图吧想了一下用并查集竟然过了,AC如下#include<bits/stdc++.h>using namespace std;int cnt, n, m;int fa[1005], size[1005];void init(){ cnt = n - 1; for(int i = 0; i <...原创 2019-07-10 17:23:59 · 126 阅读 · 0 评论 -
计蒜客-八皇后问题-深度优先搜索剪枝
题目链接按行深搜,设定三个标记数组分别标记已被占用的列、主对角线和副对角线分析可得行列号推导主对角线、副对角线下标方法AC如下#include<bits/stdc++.h>using namespace std;int amap[8][8], maxc = INT_MIN;bool val[8], sla[15], sla2[15];void dfs(int c, ...原创 2019-07-15 10:27:38 · 208 阅读 · 0 评论 -
计蒜客-网络交友-并查集
题目链接用了一个映射表维护人员序号AC代码#include<bits/stdc++.h>using namespace std;const int maxn = 10005;int p, n, fa[maxn], size[maxn];map<string, int>amap;int num(string nam){ if(amap.count(nam...原创 2019-07-15 11:23:50 · 245 阅读 · 0 评论 -
计蒜客-等边三角形-抽象dfs剪枝思路过程
题目链接动手之前要想好解空间树,解空间树是决定复杂度的关键,极端情况的微弱剪枝效果往往不佳。一开始的想法(相对麻烦,可以直接跳过)三条边的长度已知(sum),按照边的长度作为dfs的参数a遍历每条边,未被使用过且sum - a大于当前边,则将该木棍纳入该边当边长符合题目要求时,判断此时是第几条满足要求的边如果是第三条,则判断是否全部边都被使用,不是则判断为不可能,是则输出yes,结束...原创 2019-07-06 02:41:50 · 218 阅读 · 0 评论 -
JSK-美好的邂逅-最短路Floyd
题目在这Floyd 的水题AC代码#include<bits/stdc++.h>using namespace std;const int inf = 0x3f3f3f3f;const int maxn = 105;const int maxm = 205;int amap[maxn][maxn];int m, n;void floyd(){ for...原创 2019-06-23 12:25:46 · 170 阅读 · 0 评论 -
HDOJ2112-HDU Today
题目链接Problem Description经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区500强。这时候,XHD夫妇也退居了二线,并在风景秀美的诸暨市浬浦镇陶姚村买了个房子,开始安度晚年了。这样住了一段时间,徐总对当地的交通还是不太了解。有时很郁闷,想去一个地方又不知道应该乘什么公交车,在什么地方转...原创 2019-06-25 22:55:09 · 100 阅读 · 0 评论 -
HDOJ2544-Dijkstra 最短路
题目链接最短路Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 104360 Accepted Submission(s): 44860Problem Description在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮...原创 2019-06-25 21:01:21 · 141 阅读 · 0 评论 -
HDU1003-Max Sum动态规划详细解题过程
原题Problem DescriptionGiven a sequence a[1],a[2],a[3]……a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 +转载 2018-02-01 13:47:32 · 277 阅读 · 0 评论 -
HDU-1006-Tick and Tick
看了许多模板,发现还是一头雾水,而且自尊心还受到了打击,这是不正确的,先留下印象,一定要变强啊!!!原创 2018-02-07 23:54:39 · 161 阅读 · 0 评论 -
JSK-DFS-走迷宫
题目dfs水题,贴上dfs模板void dfs(int deep) { if (到达边界) { // 做一些处理后返回 } else { for(所有可能的选择) { dfs(deep + 1); } }}代码框架:// 对坐标为(x, y)的点进行搜索void dfs(int x, int ...原创 2019-05-14 12:28:14 · 183 阅读 · 0 评论 -
JSK-并查集-找朋友
题目链接简单的并查集应用,路径压缩代码:int get(int x){ if(x == father[x]; return x; return father[x] = get(father[x]);}AC警告#include<bits/stdc++.h>using namespace std;int fa[5005];int get(int x){ ...原创 2019-05-14 11:15:27 · 383 阅读 · 0 评论 -
DFS - Red and Black
There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can’...原创 2019-05-01 16:39:59 · 365 阅读 · 0 评论 -
Bee-Fibonacci
In Africa there is a very special species of bee. Every year, the female bees of such species give birthto one male bee, while the male bees give birth to one male bee and one female bee, and then th...原创 2019-05-01 16:37:55 · 291 阅读 · 0 评论 -
JSK-DFS-踏青
题目在这一道题竟然做了一节课…貌似最开始审题不清?题目没有指定草地的表示方法于是改正为遇到" . "标记为空地1,其余的默认为0深搜思路:遍历一遍二位数组,当且仅当遇到0时开始进行dfs(1)根据题意,从0开始进行四方向深搜过程中可触及的0区域均视为一个整体,故仅需在(1):遇到0,即遇到深搜标志时才将问题解++。AC警告#include<bits/stdc++.h&g...原创 2019-05-14 15:33:31 · 249 阅读 · 0 评论 -
JSK练习-水果店(映射表)
题目链接有关“映射表的映射表”的题目,AC代码:#include<bits/stdc++.h>using namespace std;set<string>p;set<string>f;map<string, map<string, int>>d;int main(){ int n; cin>&...原创 2019-06-05 12:26:56 · 254 阅读 · 0 评论 -
JSK-Floyd多源最短路水题-蒜厂年会
题目在这Floyd算法模板题AC如下#include<bits/stdc++.h>#define maxn 305using namespace std;const int INF = INT_MAX/100;int d[maxn][maxn];int n, m;void init(){ cin>>n>>m; for(int i = 1; ...原创 2019-06-09 16:55:37 · 143 阅读 · 0 评论 -
JSK-Floyd-蒜头君的训练室
题目在这划水划水,AC如下:#include<bits/stdc++.h>#define maxn 305using namespace std;const int INF = INT_MAX/100;int n, m, t, d[maxn][maxn];void init(){ cin>>n>>m>>t; for(int i ...原创 2019-06-09 17:32:29 · 122 阅读 · 0 评论 -
JSK-A1594封印之门,Floyd最短路
题目链接蒜头君被暗黑军团包围在一座岛上,所有通往近卫军团的路都有暗黑军团把手。幸运的是,小岛上有一扇上古之神打造的封印之门,可以通往近卫军团,传闻至今没有人能解除封印。封印之门上有一串文字,只包含小写字母,有 kk 种操作规则,每个规则可以把一个字符变换成另外一个字符。经过任意多次操作以后,最后如果能把封印之门上的文字变换成解开封印之门的文字,封印之门将会开启。蒜头君战斗力超强,但是不擅计算...原创 2019-06-25 12:43:22 · 298 阅读 · 0 评论 -
HDU1004-Let the Balloon Rise
题目链接#include#include#define PF printf#define SF scanfint main(){ int n, i, j, count = 1, max = 0; char color[1000][16], temp[16]; while((~SF("%d",&n)) && (n != 0)) { f原创 2018-02-01 13:35:38 · 130 阅读 · 0 评论