算法
还在学习的编程小白
大三学生 编程小白 会写一点java web小项目 一点点算法知识
展开
-
1125 Chain the Ropes (25分)
Given some segments of rope, you are supposed to chain them into one rope. Each time you may only fold two segments into loops and chain them into one piece, as shown by the figure. The resulting chai...原创 2020-01-14 19:08:29 · 137 阅读 · 0 评论 -
PAT 甲 1126 Eulerian Path (25分)
要点1:注意考察图的连通性,用dfs,看看一次dfs能否遍历所有的点,如果不联通,就不是欧拉图要点2:会出现所有的点都在边里,但还是不联通的情况,所以必须用dfs,不能直接看点有没有被输入过#include<iostream>#include<map>#include<vector>using namespace std;int n,m,cnt...原创 2020-01-14 18:25:30 · 147 阅读 · 0 评论 -
1127 ZigZagging on a Tree (30分)
要点1.根据后序和中序建立树得会要点2.记录每层的元素得会,front 和last 还有 rear的关键点,即非递归求树高#include<iostream>#include<queue>#include<stack>using namespace std;int n,post[35],in[35];struct Node{ int dat...原创 2020-01-14 16:44:51 · 132 阅读 · 0 评论 -
PAT 甲 1135 红黑二叉树
题目要点:解题的关键是理解题目所说的红黑的性质There is a kind of balanced binary search tree named red-black tree in the data structure. It has the following 5 properties: (1) Every node is either red or black....原创 2020-01-10 18:43:01 · 176 阅读 · 0 评论 -
PAT 甲 1136
知识点: 大整数加法,reverse 函数的应用要注意的点 就是输入的数本身是回文数的情况#include<iostream>#include<algorithm>using namespace std;bool isr(string s){ for(int i=0;s[i];++i){ if(s[i]!=s[s.length()-1-i]) retu...原创 2020-01-10 15:41:27 · 134 阅读 · 0 评论 -
PAT 甲级 1139
总结如果要在set或map 存结构体 就一定要重定义 "<"对于结构体数组进行排序,cmp函数是必须的格式化输出补零用%04d ,保留4位小数用%.4f当有例子过不去的时候 一定要仔细读题 把逻辑理顺题目看不懂的时候一定要仔细分析测试用例#include<iostream>#include<map>#include<vecto...原创 2020-01-09 17:42:27 · 132 阅读 · 0 评论 -
PAT 甲1140
#include<iostream>using namespace std;int d,n;string fun(string s){ int h[10]={0}; string head=""; for(int i=0;s[i];++i){ h[s[i]-'0']++; if(s[i]!=s[i+1]){ ...原创 2020-01-09 11:54:11 · 129 阅读 · 0 评论 -
PAT 甲级 1145 解题记录
//这题遇到了两个大问题//处理碰撞的函数搞错了//计算查找长度时,没有考虑 本来就没有尝试插入的情况,只考虑到插入但是失败的情况//对于探测失败 为什么到 Tsize,当j==Tsize时 j*j=Tsize*Tsize,//于是 (H(key)+j*j)%Tsize==H(key)即j=0 时的情况,即回到原来的地方了 于是当j==Tsize 查找失败 //(H(key)+j*j)...原创 2020-01-08 14:34:35 · 232 阅读 · 0 评论