![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
天梯赛
moumoumouwang
这个作者很懒,什么都没留下…
展开
-
1091 Acute Stroke (30分)[BFS]
原题链接广度优先探索 还是比较有套路的我错主要是错在了cnt++的位置要在弹出去之前cnt++ 还有要注意深度防爆栈inq[1290][130][61]AC代码:#include <iostream>#include <cstdio>#include <queue>using namespace std;const int maxn = 1290;struct node{ int x, y, z;}Node;int X[6] = {0,0,0原创 2021-03-25 12:24:03 · 52 阅读 · 0 评论 -
L2-012 关于堆的判断 (25 分)
#include <iostream>#include <cstdio>#include <vector>#include <algorithm>using namespace std;const int maxn = 1010;vector<int> v;int n, m;void upAdjust(int i){ if(i == 1) return; while(i != 1) { if(v[i] < v[i原创 2021-03-06 21:53:37 · 57 阅读 · 0 评论 -
L2-025 分而治之 (25 分)
我看这道题的时候想到的是天梯红色警报这道题,都考察了连通性问题,但这么写了一个超内存了hhh 改了半天也没改成功 应该是复原方法有问题就不该用二维数组存 后来查了优秀代码用的是度、邻接表 开个一维数组来存储每个节点的度 这样空间就是一维 不会超内存了AC代码:#include <iostream>#include <cstring>#include <vector>#include <stack>#include <algorithm>原创 2021-03-05 10:16:21 · 119 阅读 · 1 评论 -
L2-025 分而治之 (25 分)
简简单单dfs#include <iostream>#include <cstring>#include <vector>#include <stack>#include <algorithm>using namespace std;const int maxn = 100010;vector<vector<int>> Node(maxn);int s;vector<int> ans;in原创 2021-03-04 22:23:32 · 90 阅读 · 1 评论 -
L2-031 深入虎穴 (25 分)
memset(visit, true, sizeof(visit));报错 添加#include <cstring>头文件我以前怎么没发现这个问题 以为是逻辑错误卡了半天 加个头文件就啥事没有了 我一直以为memset是memory头文件里的。。老爷爷看手机.jpg#include <iostream>#include <cstring>#include <vector>using namespace std;const int maxn = 1原创 2021-03-03 17:43:37 · 117 阅读 · 1 评论 -
L1-058 6翻了 (15 分)
很easy的一道题哈 但我就是想写个题解????#include <cstdio>#include <iostream>#include <string>#include <cctype>#include <vector>#include <algorithm>using namespace std;int main(){ string str; getline(cin, str); int cont = 0原创 2021-03-03 11:08:25 · 50 阅读 · 0 评论 -
L2-020 功夫传人 (25 分)
就很灵活 dfs可以写很多种其实只要知道两点就行1、看懂题整明白功力怎么传怎么算2、判断如何到达底端了 我是通过没有孩子还可以通过是否访问过 判断标志随自己定啦#include <iostream>#include <vector>#include <map>using namespace std;const int maxn = 100010;int n;double z,r,result = 0.0;struct Node{ int id;原创 2021-02-28 21:17:33 · 45 阅读 · 0 评论 -
L2-021 点赞狂魔 (25 分)
卡了一下 输出“-”n = 0 1 2 都得自动补“-”注意一下就行 简单题#include <iostream>#include <algorithm>#include <map>#include <set>using namespace std;const int maxn = 1010;struct node{ string id; int num; int dif; double ave;}Node[maxn];bo原创 2021-02-28 21:12:27 · 87 阅读 · 0 评论 -
L2-019 悄悄关注 (25 分)
这题本身很简单 但是看了柳神的还是学到不少auto用法 很方便map容器 m->first,m->second;要善用用flag标志#include <iostream>#include <set>#include <map>using namespace std;const int maxn = 5010;int main(){ set<string> s; map<string, int> m; int n原创 2021-02-28 17:30:01 · 71 阅读 · 0 评论 -
L2-020 功夫传人 (25分)
想想是不是因为忘记存值导致结果不对还有注意理解递归里的return#include <iostream>#include <string>#include <vector>#include <algorithm>using namespace std;//const int maxn = 100010;struct node{ double data,v,power; vector<int> child; int levea原创 2021-02-02 08:38:20 · 88 阅读 · 1 评论 -
L3-003 社交集群 (30分)
原题链接并查集要想明白 合并的是什么是通过什么合并的合并的是人的编号 通过是否喜欢同一个活动x进行判断1、int course[x]; //喜欢活动x的人的编号 如果这个活动没人喜欢过就要设置course[x] = i;喜欢过的话就合并2、findfather(course[x]) 喜欢活动x的人所在的社交圈子的根结点,需要与当前编号i进行合并。#include <iostream>#include <string>#include <queue>#inc原创 2021-02-01 11:22:04 · 84 阅读 · 0 评论 -
L1-043 阅览室 (20分)
原题链接这道题我是以E为判断组合标准的1 3测试点无法通过是因为没有考虑到S E E的情况visit[id] = true; //解决S E E 的情况加个判断标志就好啦#include <iostream>#include <string.h>using namespace std;const int maxn = 10010;struct read{ string s; int hh,mm;}per[maxn];bool visit[maxn] ={f原创 2021-01-30 18:08:08 · 81 阅读 · 0 评论 -
L2-026 小字辈 (25分)
原题链接嘻BFSDFSBFS结构体存孩子,以及层数BFS每次访问的加入的是节点queue<int> q;对应操作的是他的孩子Node[Node[now].child[i]]和他孩子的层数Node[Node[now].child[i]].leval直接存节点就是思路比较简单但是表示起来好长hhhh每次便利需要记录最大层数maxleval,存储对应的节点vector<int> ans需要注意:ans.clear(); ans.push_back(now); //清空原创 2021-01-30 12:44:11 · 58 阅读 · 0 评论 -
L2-023 图着色问题 (25分)
原题链接#include <iostream>#include <set>#include <vector>using namespace std;//颜色不到6个直接剔除//存相邻的边 查看相邻点颜色是否相同const int maxv = 501;int v, e,k;vector<int> color(maxv);vector<vector<int>> vi(maxv);bool visit[maxv] =原创 2021-01-29 18:55:36 · 71 阅读 · 0 评论 -
L2-022 重排链表 (25分)
原题连接测试点 1 31 是没有多余节点的奇数节点样例3是有多余节点的奇数节点测试样例最近几道题都是第一遍19分害 链表题其实蛮有固定思路的 我就是总记不住更新有效节点 在输出格式的时候还是会习惯性的使用原始节点个数AC代码:#include <iostream>#include <stack>#include <map>#include <cmath>#include <algorithm>using namespace s原创 2021-01-19 19:49:58 · 72 阅读 · 0 评论 -
L2-032 彩虹瓶 (25分)
原题链接第一次测试样例124没有过,错误点在于先入栈再判断,这样无法处理假设栈最大值为5 输入7 6 5 4 3 1 2这样的问题,按照此例子应该是YES但是由于先进栈导致栈满flag为false输出NOAC代码:#include <iostream>#include <stack>#include <map>#include <cmath>using namespace std;const int maxn = 10010;int n,m原创 2021-01-19 16:34:47 · 232 阅读 · 1 评论 -
L1-2 6翻了 (15分)
it is so 666 really 6666 what else can I say 6666666666输出样例:it is so 666 really 9 what else can I say 27扫描 不是6就直接输出 遇到6停止扫描进行个数num统计 直到碰到再次不是6的数字进行输出 但在此之前先输出6的格式变换输出 具体格式转化就看题就行 不难理解注意的就是 for(int I = 0;) I要初始化 要不各种错误 枯了 今天真的碰到好多这种容易被忽略但是一卡一个准的点 害A.原创 2020-11-12 23:29:11 · 119 阅读 · 0 评论 -
L2-3 玩转二叉树 (25分)
71 2 3 4 5 6 74 1 3 2 6 5 7输出样例:4 6 1 7 5 3 2不知道说啥了 超无语的一道题 觉得没错但是一直段错误段错误部分:int k; for(int k;......)这样写是不对的 再加上下边还要用到k值所以还一定要在外部声明k 所以正确写法只有下边这样了:int k;//在中序序列中寻找k for(k = inl; k <= inr; k++) { if(in[k] == pre[prel]) { break; } }.原创 2020-11-12 22:42:15 · 350 阅读 · 0 评论 -
L2-023 图着色问题 (25分)
6 8 32 11 34 62 52 45 45 63 641 2 3 3 1 24 5 6 6 4 51 2 3 4 5 62 3 4 2 3 4输出样例:YesYesNoNo啊 这题 一句话就是看连通的两端点颜色是否相同是否联通 也就是是否可达 无向图存储然后设置初始值就完事了颜色就另开一个数组呗对应着端点做为下标来存唯一注意的点就是每次输入测试组测试完的时候set要清除一下要不对下一组的测试会产生影响#include <iostream>.原创 2020-11-12 20:37:06 · 115 阅读 · 0 评论 -
L2-1 链表去重 (25分)
00100 599999 -7 8765423854 -15 0000087654 15 -100000 -15 9999900100 21 23854输出样例:00100 21 2385423854 -15 9999999999 -7 -100000 -15 8765487654 15 -1静态链表的使用 利用容器 不删的存在save中 删除的存在deleat中 是否删除的标准为绝对值键值不可以重复,那就开一个bool vis[N] = {false};类似哈希表做一个映射作.原创 2020-11-12 16:30:17 · 244 阅读 · 0 评论 -
L1-5 就不告诉你 (15分)
输入格式:输入在第一行给出两个不超过 1000 的正整数 A 和 B,其间以空格分隔。输出格式:在一行中倒着输出 A 和 B 的乘积。输入样例:5 7输出样例:53水题 但是注意省略前置0 105 * 2 = 210 要输出12#include <iostream>#include <cstdio>#include <string>using namespace std;int main(){ int a,b; cin >原创 2020-11-11 22:04:19 · 573 阅读 · 0 评论 -
L1-1 帅到没朋友 (20分)
33 11111 22222 555552 33333 444444 55555 66666 99999 77777855555 44444 10000 88888 22222 11111 23333 88888输出样例:10000 88888 23333#include <iostream>#include <algorithm>#include <vector>using namespace std;bool havefrind[11.原创 2020-11-11 20:07:40 · 212 阅读 · 4 评论 -
L1-033 出生年 (15分)
#include <bits/stdc++.h>using namespace std; //树塔问题string str;set<char> s;int n, y, cnt = 0;int main(){ cin >> y >> n; while(s.size() != n) { s.clear(); str = to_string(y + cnt++); while(s原创 2020-10-25 12:59:45 · 60 阅读 · 0 评论 -
2020-10-25
整体思路其实并不难,比较巧妙地应该判断出相邻点颜色相同利用break进行No输出的时候是利用外函数写把二次循环变成一次循环。#include <bits/stdc++.h>using namespace std;vector<vector<int>> v(510);vector<int> color(510);int n, e, k;bool f(int i) //第i个顶点的连通情况{ for(int j = 0; j < v[i原创 2020-10-25 11:06:58 · 63 阅读 · 0 评论 -
L1-054 福到了【字符串处理】
#include <bits/stdc++.h>using namespace std;int main(){ char c; int n, flag = 0; scanf("%c%d", &c, &n); getchar(); vector<string> a(n); for(int i = 0; i < n; i++) { getline(cin, a[i]); }原创 2020-10-25 09:45:59 · 55 阅读 · 0 评论 -
L1-039 古风排版 (20分)【字符串处理】
原题链接思路:修正字符串 扫描字符串 按对四取余为下标分类 开数组存储 倒着输出就ok#include <bits/stdc++.h>using namespace std;string str;int main(){ int n; cin >> n; getchar(); string str; getline(cin, str); int flen = str.length(); //初始字符串长度 int原创 2020-10-25 09:13:50 · 176 阅读 · 0 评论 -
L1-027 出租 (20分)
原题链接STL set从大到小排序字符串转化成数组 是char->int 要做处理map数组下标映射 for(int i = 0; i < telnumber.length(); i++) { int x = telnumber[i] - '0'; arr.insert(x); }#include <bits/stdc++.h>using namespace std;struct compare{ bool原创 2020-09-18 16:44:00 · 73 阅读 · 0 评论 -
7-6 愿天下有情人都是失散多年的兄妹 (25分)
呵呵。大家都知道五服以内不得通婚,即两个人最近的共同祖先如果在五代以内(即本人、父母、祖父母、曾祖父母、高祖父母)则不可通婚。本题就请你帮助一对有情人判断一下,他们究竟是否可以成婚?输入格式:输入第一行给出一个正整数N(2 ≤ N ≤104 ),随后N行,每行按以下格式给出一个人的信息:本人ID 性别 父亲ID 母亲ID其中ID是5位数字,每人不同;性别M代表男性、F代表女性。如果某人的父亲或母亲已经不可考,则相应的ID位置上标记为-1。接下来给出一个正整数K,随后K行,每行给出一对有原创 2020-08-19 10:14:07 · 1306 阅读 · 1 评论 -
L2-001 城市间紧急救援 (25分)
作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图。在地图上显示有多个分散的城市和一些连接城市的快速道路。每个城市的救援队数量和每一条连接两个城市的快速道路长度都标在地图上。当其他城市有紧急求助电话给你的时候,你的任务是带领你的救援队尽快赶往事发地,同时,一路上召集尽可能多的救援队。输入格式:输入第一行给出4个正整数N、M、S、D,其中N(2≤N≤500)是城市的个数,顺便假设城市的编号为0 ~ (N−1);M是快速道路的条数;S是出发地的城市编号;D是目的地的城市编号。第二行给出N个正整数原创 2020-08-26 12:25:57 · 903 阅读 · 0 评论 -
7-19 敲笨钟
微博上有个自称“大笨钟V”的家伙,每天敲钟催促码农们爱惜身体早点睡觉。为了增加敲钟的趣味性,还会糟改几句古诗词。其糟改的方法为:去网上搜寻压“ong”韵的古诗词,把句尾的三个字换成“敲笨钟”。例如唐代诗人李贺有名句曰:“寻章摘句老雕虫,晓月当帘挂玉弓”,其中“虫”(chong)和“弓”(gong)都压了“ong”韵。于是这句诗就被糟改为“寻章摘句老雕虫,晓月当帘敲笨钟”。现在给你一大堆古诗词句,要求你写个程序自动将压“ong”韵的句子糟改成“敲笨钟”。输入格式:输入首先在第一行给出一个不超过 20 的原创 2020-08-24 12:21:43 · 323 阅读 · 0 评论 -
7-14 福到了
原题链接思路:int s[maxn][maxn] 输入标记矩阵int a[maxn][maxn] 存储倒过来的输入标记矩阵1.输入 输入时设置标记 区分字符以及空格 用于判断以及输出2.判断 设置标记 判断s, a是否一致3.输出 根据标记输出相应符号以及空格。#include <iostream>#include <cstdio>#include <string>using namespace std;const int maxn = 110;i原创 2020-08-23 23:29:37 · 175 阅读 · 0 评论 -
L1-049 天梯赛座位分配
原题链接思路:参考文章1.椅子不动 给椅子分配人2.如果学校还有人没有被安排,那就要安排座位,安排的方案:如果前边座位不是本校生,直接坐,并标记此座位的学校id;如果前边座位是本校生,那就要让这个学生做下一把椅子,并标记椅子的后一把的学校id;3.设置flag标志,如果所有的学校学生都被安排座位,说明安排完毕,可退出。#include <iostream>#include <cstdio>#include <algorithm>#include <原创 2020-08-23 16:17:38 · 217 阅读 · 0 评论 -
7-8 矩阵A乘以B
给定两个矩阵A和B,要求你计算它们的乘积矩阵AB。需要注意的是,只有规模匹配的矩阵才可以相乘。即若A有Ra 行、Ca 列,B有Rb 行、Cb 列,则只有Ca 与Rb 相等时,两个矩阵才能相乘。输入格式:输入先后给出两个矩阵A和B。对于每个矩阵,首先在一行中给出其行数R和列数C,随后R行,每行给出C个整数,以1个空格分隔,且行首尾没有多余的空格。输入保证两个矩阵的R和C都是正数,并且所有整数的绝对值不超过100。输出格式:若输入的两个矩原创 2020-08-22 15:40:57 · 242 阅读 · 0 评论 -
7-6 整除光棍
目录思路分析反思总结附测试点:AC代码思路分析参考文章1.输入x循环找到第一个大于等于x的num同时计数;2.输出num / x 也就是num的第一位 对余数做运算num = (num % x) * 10 + 1并同时计数 直到(num % x) == 0退出循环 输出num的每一位 以及 cnt反思总结1.数学问题还是要利用数学思维来求解 利用循环按位输出直接解决了 存储数据空间问题2.这道题利用的余数按位求解的数学方法是我一开始没想到的,先求num再除可能会导致超时超空间。分步求解就可以完原创 2020-08-22 13:28:15 · 129 阅读 · 0 评论 -
7-3 阅览室
天梯图书阅览室请你编写一个简单的图书借阅统计程序。当读者借书时,管理员输入书号并按下S键,程序开始计时;当读者还书时,管理员输入书号并按下E键,程序结束计时。书号为不超过1000的正整数。当管理员将0作为书号输入时,表示一天工作结束,你的程序应输出当天的读者借书次数和平均阅读时间。注意:由于线路偶尔会有故障,可能出现不完整的纪录,即只有S没有E,或者只有E没有S的纪录,系统应能自动忽略这种无效纪录。另外,题目保证书号是书的唯一标识,同一本书在任何时间区间内只可能被一位读者借阅。输入格式:输入在第一行原创 2020-08-21 18:58:42 · 162 阅读 · 0 评论