自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

北冥有鱼

培风图南

  • 博客(176)
  • 收藏
  • 关注

原创 7-2 Merging Linked Lists

原来L1 和 L2 不一定是 L1 》#include <iostream>#include <vector>#include <algorithm>using namespace std;int const maxn = 100010;struct node{ int first, data, next;}Node[maxn];int mai...

2020-02-08 18:10:55 1346

原创 7-3 Postfix Expression

这个题目主要是对于单个孩子节点是先序遍历,需要区分下。#include <iostream>#include <algorithm>using namespace std;int const maxn = 25;struct node{ string data; int left = -1, right = -1;}Node[maxn];bool isro...

2020-02-08 18:05:10 956

原创 7-4 Dijkstra Sequence

这个题目一定要理解题意,{ 5, 1, 3, 4, 2 } and { 5, 3, 1, 2, 4 } 明显在说不是要求图遍历的路径,如果使用 pre[maxn] 记录路径,就错了。#include <iostream>#include <vector>#include <algorithm>using namespace std;int const ...

2020-02-08 18:02:37 801

原创 7-1 Forever

A 和 A + 1 肯定是互质的,因此A必然以 9 结尾。然后找规律:末尾一个9, m 与 n 相差 8;末尾两个9, m 与 n 相差 17;可得 m - n + 1 为 9 的倍数,从而可以较快遍历找到 n, 找到 n 后,根据倍数可以知道末尾 9 的个数,对 A 头部非 9 的部分进行遍历,快速得到 A;#include <iostream>#include <c...

2020-02-08 17:56:38 269

原创 1143 Lowest Common Ancestor

#include <iostream>#include <map>using namespace std;const int maxn = 10010;int rec[maxn];map<int, bool> exsit;int main(){ int n, m; cin >> n >> m; for(int i = 0...

2020-01-28 16:23:19 98

原创 1082 Read Number in Chinese

这个题目真恶心。费老大劲了。#include <iostream>using namespace std;string s1[11] = {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"};string s2[11] = {"Yi", "Qian", "Bai", "Shi", "Wan", "Qi...

2020-01-28 15:13:36 100

原创 1071 Speech Patterns

#include <map>#include <algorithm>#include <iostream>using namespace std;int main(){ string s, temp; map<string, int> ma; getline(cin, s); for(int i = 0; i < s.lengt...

2020-01-27 21:34:21 3376

原创 1129 Recommendation System

#include <iostream>#include <set>using namespace std;const int maxn = 50010;int fre[maxn] = {0};struct node{ int data, fre; bool operator < (const node &a) const{ return fr...

2020-01-27 21:05:46 181

原创 7-1 Good in C (20分)

坑壁的题目,比30分的还坑,分隔符可能是空格!所以一定用getline,而且居然用了三重循环。。。#include <iostream>#include <vector>using namespace std;int main(){ vector<string> v[26], word; string s, temp; for(int i = 0;...

2020-01-27 19:30:08 496 1

原创 1045 Favorite Color Stripe

#include <iostream>#include <algorithm>using namespace std;const int maxn = 10010;int dp[maxn], ans = -1, A[maxn], order[maxn] = {0}, cnt = 0;int main(){ int n, m, k, num; cin >&...

2020-01-27 11:57:29 201

原创 1040 Longest Symmetric String

#include <iostream>#include <algorithm>using namespace std;const int maxn = 1005;string s;int dp[maxn][maxn], ans = 1;int main(){ getline(cin, s); fill(dp[0], dp[0] + maxn * maxn, ...

2020-01-27 11:14:13 100

原创 1119 Pre- and Post-order Traversals

这个题将先序和后序遍历序列转化成中序遍历序列,形式依然如同中序遍历,先往左子树,输出根节点,再往右子树。但是对于in.push_back(pre[preL]);我同时在这个位置打印这个值,只能得到三个结果,这是为什么。对先序中序后序遍历还是需要总结下#include <iostream>#include <vector>using namespace std;co...

2020-01-26 19:55:06 130

原创 1110 Complete Binary Tree

一般在用队列进行层序遍历时候,遇到node 左右子树为-1时,是return的,但如果要检查一棵树是不是完全二叉树,就不用return了,而是把-1也压进队列,如果在遍历的中途,队列中出现了-1,即说明不是完全二叉树。如果要检查是否为满二叉树,判断遍历完成后,node数是否等于2的level次-1即可。#include <iostream>#include <queue&gt...

2020-01-26 19:04:42 369

原创 1014 Waiting in Line

逻辑没有错啊,最后一个测试点过不了#include <iostream>#include <queue>using namespace std;const int maxn = 1005;int n, m, k, query;struct node{ int selftime, starttime;}Cus[maxn];int main(){ cin &...

2020-01-26 15:03:25 86

原创 1153 Decode Registration Card of PAT

读入原始数据的时候,最好不做处理,保持原始数据的完整性,之后再根据条件进行处理。简洁良好的node结构很重要。#include <iostream>#include <vector>#include <unordered_map>#include <algorithm>using namespace std;const int maxn...

2020-01-24 10:46:22 122

原创 1149 Dangerous Goods Packaging

最后一个测试点错误,思路是用map对应vector存储所有与key 不相容的物品。对于query,建立一个空数组,对每个key, 遍历与其不相容的物品编号,在数组中全部记为1。后入的key在数组中查值,如果值为1,说明不相容,如果没有不相容的,将自己不相容的物品编号也记录到数组中,继续查找下一个key。因为是ab两两不相容,因此,理论上思路应该是对的,可是为什么最后一个测试点错误?#incl...

2020-01-23 16:26:23 284 2

原创 1142 Maximal Clique

#include <iostream>#include <vector>using namespace std;int main() { int nv, ne, m, k, a, b, c; cin >> nv >> ne; vector<int> v[nv + 1], temp; for(int i = 0; i <...

2020-01-23 13:06:29 126

原创 1141 PAT Ranking of Institutions

这个题就是要注意下总成绩的格式问题,统计的时候要用double进行累加,排序前要转换成去掉小数部分的int。#include <iostream>#include <vector>#include <map>#include <cctype>#include <algorithm> using namespace std;s...

2020-01-23 11:34:53 88

原创 1074 Reversing Linked List

所有链表相关的题目都有可能存在给出的node数量大于有效节点数的情况,所以在代码过程中,需要重新获得总的有效节点数。另外,分段遍历的标准写法需要记一下: for(int i = 0; i < size - size % k; i += k)#include <iostream>#include <vector>#include <algorithm&...

2020-01-23 10:29:03 363

原创 1137 Final Grading

#include <iostream>#include <vector>#include <map>#include <algorithm>using namespace std;const int maxn = 111;struct node{ string id; int gp, gm = -1, gf, gg;}stu[max...

2020-01-22 20:17:28 92

原创 1134 Vertex Cover

#include <iostream>#include <vector>using namespace std;int main(){ int n, m, a, b, q, k, c; cin >> n >> m; vector<int> v[n]; for(int i = 0; i < m; i++){ cin ...

2020-01-22 19:25:43 96

原创 1130 Infix Expression

#include <iostream>using namespace std;const int maxn = 25;struct node{ string op; int lchild, rchild;}Node[maxn];int isRoot[maxn] = {0};int n, root = 1; void inorder(int r){ if(r == -...

2020-01-22 17:13:20 136

原创 1127 ZigZagging on a Tree

#include <iostream>#include <queue>#include <stack>using namespace std;const int maxn = 501;struct node{ int data, layer; node *lchild, *rchild;};int n, recpo[maxn], recin[m...

2020-01-22 14:49:52 98

原创 1126 Eulerian Path

#include <iostream>#include <vector>#include <algorithm>using namespace std;const int maxn = 501;vector<int> v[maxn];bool vis[maxn] = {false};void dfs(int index){ vis[i...

2020-01-22 13:18:49 81

原创 1123 Is It a Complete AVL Tree

#include <iostream>#include <queue>using namespace std;struct node{ int data, height; node *lchild, *rchild;};int getHeight(node* root){ if(root == NULL) return 0; return root-&gt...

2020-01-22 12:23:18 58

原创 1122 Hamiltonian Cycle

#include <iostream>using namespace std;const int maxn = 201;int G[maxn][maxn];int main(){ fill(G[0], G[0] + maxn * maxn, 0); int n, m, a, b, q, k, st, t; cin >> n >> m; for(i...

2020-01-22 10:09:24 138

原创 1114 Family Property

#include <iostream>#include <vector>#include <algorithm>using namespace std;const int maxn = 10010;struct node{ int id, num = 0, set, area, minid = maxn; double avgset, avgare...

2020-01-21 22:47:36 97

原创 1118 Birds in Forest

#include <iostream>#include <algorithm>using namespace std;const int maxn = 10010;int isRoot[maxn] = {0}, rec[maxn] = {0}, father[maxn];int find(int x){ int a = x; while(x != father...

2020-01-21 21:44:09 58

原创 1115 Counting Nodes in a BST

#include <iostream>#include <queue>using namespace std;const int maxn = 1001;int rec[maxn] = {0}; struct node{ int data, layer; node *lchild, *rchild;};void insert(node* &root...

2020-01-21 18:34:19 83

原创 1111 Online Map

#include <iostream>#include <vector>#include <cstring>using namespace std;const int maxn = 501;const int inf = 1000000000;int D[maxn][maxn], T[maxn][maxn], d[maxn], t[maxn], n,...

2020-01-21 16:25:05 76

原创 1070 Mooncake

注意,结构体里的库存也要用double类型。#include <iostream>#include <algorithm>using namespace std;const int maxn = 1001;struct node{ double kusun, zongjia, danjia;}Node[maxn];bool cmp(node a, node ...

2020-01-20 22:34:57 85

原创 1046 Shortest Distance

#include <iostream>#include <algorithm>using namespace std;const int maxn = 100001;int rec[maxn] = {0};int main(){ int n, m, num, sum = 0; cin >> n; for(int i = 1; i <= n;...

2020-01-20 19:34:21 161

原创 1036 Boys vs Girls

#include <iostream>#include <vector>#include <algorithm>using namespace std;struct node{ string name, gender, id; int grade;};bool cmp(node a, node b){ return a.grade < b...

2020-01-20 19:06:59 79

原创 1019 General Palindromic Number

#include <iostream>#include <algorithm>using namespace std;int main(){ int n, b, flag = 1, num[1000], cnt = 0; cin >> n >> b; do{ num[cnt++] = n % b; n /= b; }...

2020-01-20 18:41:32 75

原创 1011 World Cup Betting

#include <iostream>#include <map>using namespace std;int main(){ map<int, char> ma; char ch[4] = "WTL"; double ans = 1, odd; for(int i = 0; i < 3; i++){ double temp = 1;...

2020-01-20 17:25:14 78

原创 1007 Maximum Subsequence Sum

#include <iostream>using namespace std;const int maxn = 10010;int rec[maxn], dp[maxn], s[maxn] = {0};int main(){ int n, flag = 0; cin >> n; for(int i = 0; i < n; i++){ cin >...

2020-01-20 16:14:42 59

原创 1087 All Roads Lead to Rome

#include <iostream>#include <vector>#include <map>#include <algorithm>using namespace std;const int maxn = 210;const int inf = 1000000000;int G[maxn][maxn], d[maxn], w[m...

2020-01-20 14:47:50 78

原创 1072 Gas Station

#include <iostream>#include <vector>#include <cstring>#include <algorithm>using namespace std;const int maxn = 1200;const int inf = 1000000000;int G[maxn][maxn], d[maxn]...

2020-01-19 23:17:09 71

原创 1030 Travel Plan

暂时不理解为何在判断第二标尺时,要从后往前遍历#include <iostream>#include <queue>#include <cstring>#include <algorithm>using namespace std;const int maxn = 501;const int inf = 1000000000;int ...

2020-01-19 21:30:13 100

原创 1018 Public Bike Management

#include <iostream>#include <queue>#include <cstring>#include <algorithm>using namespace std;const int maxn = 510;const int inf = 1000000000;int G[maxn][maxn], d[maxn], ...

2020-01-19 20:18:14 77

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除