自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(171)
  • 收藏
  • 关注

原创 PAT-2021年冬季考试(满分)

PAT-2021年冬季考试 - Advanced Level 贴贴这次满分的代码 7-1 Fake News (20 分) #include <iostream> #include <map> using namespace std; int a[10010], vis[10010]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, x; cin >> n >> m; w

2021-12-21 19:32:08 779

原创 pat甲级2021冬季考试(满分)

满分!!!第一次参加pat甲级就满分了很开心哈哈哈,看来这几天刷题没有白费哈哈。当时那个小时%24卡了我一个多小时,差点心态没了,还好被我意识到了哈哈哈

2021-12-19 16:38:30 1191 3

原创 520 钻石争霸赛 2022(满分)

前言 单身狗不就来刷刷题咯,今年比较简单 文章目录前言7-1 520表白7-2 分糖豆7-3 约会App7-4 关于奇数的等式7-5 我侬数7-6 非诚勿扰7-7 新式六合彩7-8 521序列 7-1 520表白 在 520 这个日子里,拼题 A 请你实现一个小功能,帮助用户向自己喜欢的数字表白。 输入格式: 输入在一行中给出一个不超过 1000 的正整数 N,是用户最喜欢的一个数字。 输出格式: 在一行中按以下格式输出对 N 的表白: N! 520! 输入样例: 233 输出样例: 233! 520!

2022-05-21 00:24:41 471

原创 各种模板汇总

前言 存一些自己以前写的模板,方便自己找 文章目录前言一、最短路1. spfa2.二、总结 一、最短路 1. spfa #include <iostream> #include <cstring> #include <queue> using namespace std; const int inf = 0x3f3f3f3f, N = 2e5 + 10; int e[N], w[N], ne[N], h[N], vis[N], dis[N], ret, n, m;

2022-04-07 12:44:34 865

原创 PTA-复数四则运算 (15 分)(最简写法)

PTA-复数四则运算 (15 分) 像这种四则运算模拟,这样写最简单清晰了。 #include <iostream> #include <cmath> #include <cstring> using namespace std; void f(double x, double y, int t) { if(t == 1){ if(y < 0) printf("(%.1lf%.1lfi)", x, y); else printf("(%.1lf+%.1lf

2022-04-05 10:27:16 1175

原创 刷题个人笔记

前言 写一些刷题中经常忘记的用法。(想到啥就更新啥) 文章目录前言一、字符串篇1.多组输入,以回车结束2.stringstream (处理空格分离的字符串)3.sscanf 和 sprintf二、重载运算符1.结构体内重载 一、字符串篇 1.多组输入,以回车结束 string s; int x; while(cin >> s >> x) { ... if(cin.get() == '\n') break; } 2.stringstream (处理空格分离的字符串) st

2022-03-26 22:30:45 823

原创 二分查找算法代码详细理解

前言 以前写了好多次的二分查找了,但对于一些细节感觉还是没有领悟道,比如while循环里面是否加上等号,mid是否要加一等等,每次写的时候虽然都过了,但总感觉是稀里糊涂的过的,这次特意来深度理解下二分,解决自己所有困惑的地方。(不断更新) 文章目录前言一、基本框架(数组查找某个数位置)二、灵活运用(数组查找第一个 >= k 的位置) 一、基本框架(数组查找某个数位置) 核心代码: int l = 0, r = len - 1, ans; while(l <= r) { int mid =

2022-03-24 22:56:58 2907

原创 1155 Heap Paths (30 分)

1155 Heap Paths (30 分) #include <iostream> #include <vector> using namespace std; vector<int> v; int a[1010], n, maxn = 1, minn = 1; void dfs(int u) { if(u > n) return; v.push_back(a[u]); dfs(u * 2 + 1); dfs(u * 2); for(int i = 1;

2022-02-23 22:53:32 104

原创 1151 LCA in a Binary Tree (30 分)

1151 LCA in a Binary Tree (30 分) #include <iostream> #include <map> using namespace std; map<int, int> m; int pre[10010], in[10010], n, M, x, y; void dfs(int root, int l1, int l2) { if(l1 > l2) return; int proot = m[pre[root]], px =

2022-02-23 22:52:58 107

原创 1147 Heaps (30 分)

1147 Heaps (30 分) #include <iostream> using namespace std; int a[2010], post[1010], ret, n, m, maxn, minn; void dfs(int u) { if(u > n) return; dfs(u * 2); dfs(u * 2 + 1); post[ret++] = a[u]; } int main() { cin >> m >> n; while(m-

2022-02-23 22:52:20 97

原创 1143 Lowest Common Ancestor (30 分)

1143 Lowest Common Ancestor (30 分) #include <iostream> #include <map> using namespace std; map<int,int> m; int a[10100]; int main() { int n, M, x, y, t; cin >> M >> n; for(int i = 0; i < n; ++i){ cin >> a[i]; m

2022-02-23 22:51:49 111

原创 1139 First Contact (30 分)

1139 First Contact (30 分) 思路有空更新 #include <iostream> #include <algorithm> #include <vector> #include <map> using namespace std; struct node{ int x, y; }; vector<int> v[10000]; map<int, map<int, int>> m; bool cmp(n

2022-02-23 22:51:18 163

原创 1135 Is It A Red-Black Tree (30 分)

1135 Is It A Red-Black Tree (30 分) #include <iostream> using namespace std; struct node{ int val; struct node *left, *right; }; int a[50], n, k; node *build(node *root, int v) { if(root == NULL){ root = new node(); root->val = v; root-&g

2022-02-23 22:50:45 106

原创 1127 ZigZagging on a Tree (30 分)

1127 ZigZagging on a Tree (30 分) 思路有空更新 #include <iostream> #include <queue> #include <vector> using namespace std; struct node{ int l, r, h; }a[10050]; vector<int> v[40]; int in[40], post[40], maxh; int dfs(int l, int l1, int l2,

2022-02-23 22:49:00 109

原创 1123 Is It a Complete AVL Tree (30 分)

1123 Is It a Complete AVL Tree (30 分) 模板题 #include <iostream> using namespace std; int tree[500]; struct node{ int val; struct node *left, *right; }; node *rotateLeft(node *root) { node *t = root->right; root->right = t->left; t->lef

2022-02-23 22:48:15 132

原创 1119 Pre- and Post-order Traversals (30 分)

1119 Pre- and Post-order Traversals (30 分) 思路有空更新 #include <iostream> using namespace std; int pre[40], post[40], in[40], ret, f; void dfs(int l1, int l2, int l3, int l4) { if(l1 > l2) return; if(l1 == l2){ in[ret++] = pre[l1]; return; } i

2022-02-23 22:47:38 95

原创 1115 Counting Nodes in a BST (30 分)

1115 Counting Nodes in a BST (30 分) 思路有空更新 #include <iostream> using namespace std; int level[1100], maxh; struct node{ int value; struct node *left, *right; }; node* build(node *root, int x) { if(root == NULL) { root = new node(); root->va

2022-02-23 22:45:35 93

原创 1111 Online Map (30 分)

1111 Online Map (30 分) 思路有空更新 #include <iostream> #include <cstring> #include <vector> using namespace std; const int inf = 0x3f3f3f3f; vector<int> p1, p2; int map1[550][550], map2[550][550], vis[550], dis[550], fast[550], cnt[550]

2022-01-29 21:02:04 194

原创 1107 Social Clusters (30 分)

1107 Social Clusters (30 分) 思路有空更新 #include <iostream> #include <set> #include <algorithm> using namespace std; int fa[2500], ret[2500]; set<int> s; int find(int x) { if(fa[x] == x) return x; else return fa[x] = find(fa[x]); } int

2022-01-29 21:01:00 90

原创 1103 Integer Factorization (30 分)

1103 Integer Factorization (30 分) 思路有空更新 #include <iostream> #include <cmath> #include <vector> using namespace std; int a[25], N, n, k, p, maxf; vector<int> b(450), ans(450); void dfs(int x, int len, int sumf, int sum) { if(len &

2022-01-29 20:59:30 219

原创 1099 Build A Binary Search Tree (30 分)

1099 Build A Binary Search Tree (30 分) 思路有空更新 #include <iostream> #include <algorithm> #include <queue> using namespace std; struct node{ int l, r, value; }a[200]; int b[200], ret; void dfs(int x) { if(a[x].l != -1) dfs(a[x].l); a[x].

2022-01-29 20:58:53 288

原创 1095 Cars on Campus (30 分)

1095 Cars on Campus (30 分) 思路有空更新 #include <iostream> #include <vector> #include <map> #include <algorithm> using namespace std; struct node{ string id; int time, flag; }a[10010]; vector<node> v; map<string, int> m;

2022-01-29 20:46:07 186

原创 1091 Acute Stroke (30 分)

1091 Acute Stroke (30 分) 思路有空更新 #include <iostream> #include <queue> using namespace std; int dir[6][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}; struct node{ int x, y, z; }; int a[1300][130][70], vis[1300][130][

2022-01-29 20:45:23 240

原创 1087 All Roads Lead to Rome (30 分)

1087 All Roads Lead to Rome (30 分) 思路有空更新 #include <iostream> #include <cstring> #include <map> using namespace std; const int inf = 0x3f3f3f3f; int e[250][250], vis[250], dis[250], path[250], ret[250], cnt[250], a[250], aa[250]; double a

2022-01-29 20:44:47 564

原创 1080 Graduate Admission (30 分)

1080 Graduate Admission (30 分) 思路有空更新 #include <iostream> #include <vector> #include <algorithm> using namespace std; struct node{ int id, ge, gi, r, admit; double avg; int ch[10]; }a[40050]; int b[150]; vector<int> v[150]; bool

2022-01-29 20:43:41 208

原创 1076 Forwards on Weibo (30 分)

1076 Forwards on Weibo (30 分) 思路有空更新 #include <iostream> #include <cstring> #include <vector> #include <queue> using namespace std; vector<int> v[1050]; int n, l, k, x, m, vis[1050]; int bfs(int x){ int level = 0, ret = 0; q

2022-01-29 20:42:59 93

原创 1072 Gas Station (30 分)

1072 Gas Station (30 分) #include <iostream> #include <cstring> using namespace std; const int inf = 0x3f3f3f3f; int map[1050][1050], vis[1050], dis[1050]; int n, m, k, ds; void dijkstra(int s){ memset(vis, 0, sizeof vis); memset(dis, inf, siz

2022-01-29 20:42:11 158

原创 1068 Find More Coins (30 分)

1068 Find More Coins (30 分) #include <iostream> #include <vector> #include <algorithm> using namespace std; const int inf = 0x3f3f3f3f; vector<int> ans; int dp[10010], v[10010], vis[10010][110]; int main() { int n, m; cin >&gt

2022-01-27 23:54:37 114

原创 1064 Complete Binary Search Tree (30 分)

1064 Complete Binary Search Tree (30 分) #include <iostream> #include <algorithm> using namespace std; int a[1050], tree[1050], n, ret; void dfs(int root){ if(root > n) return; dfs(root * 2); tree[root] = a[ret++]; dfs(root * 2 + 1); }

2022-01-27 23:51:17 353

原创 1057 Stack (30 分)

1057 Stack (30 分) #include <iostream> #include <stack> using namespace std; const int N = 1e5 + 10; int a[N]; stack<int> s; int lowbit(int x){ return x & -x; } void add(int x, int y){ for(int i = x; i < N; i += lowbit(i)) a[i]

2022-01-27 23:47:33 95

原创 1053 Path of Equal Weight (30 分)

1053 Path of Equal Weight (30 分) 思路有空更新 #include <iostream> #include <algorithm> #include <vector> using namespace std; vector<int> v[1010], path[1010]; int weight[1010], a[1010]; int n, m, s, ret; void dfs(int x, int h, int sum) {

2022-01-27 23:40:51 104

原创 1049 Counting Ones (30 分)

1049 Counting Ones (30 分) 思路有空更新 #include <iostream> using namespace std; int main(){ int n, wei = 1, now, left, right, ans = 0; cin >> n; while(n / wei){ now = n / wei % 10; //此时位上数字 left = n / (wei * 10); //左边数字 right = n % wei;

2022-01-27 23:38:24 185

原创 1045 Favorite Color Stripe (30 分)

1045 Favorite Color Stripe (30 分) 思路有空更新 #include <iostream> using namespace std; int a[10010], vis[10010], dp[10010]; int main() { int n, m, l, x, ret = 0; cin >> n >> m; for(int i = 1; i <= m; ++i){ cin >> x; vis[x] = i;

2022-01-27 23:37:49 191

原创 1038 Recover the Smallest Number (30 分)

1038 Recover the Smallest Number (30 分) 思路有空更新 #include <iostream> #include <algorithm> #include <vector> using namespace std; bool cmp(string a, string b){ return a + b < b + a; } int main() { int n; cin >> n; vector<stri

2022-01-27 23:37:13 70

原创 1034 Head of a Gang (30 分)

1034 Head of a Gang (30 分) 思路有空更新 #include <iostream> #include <map> using namespace std; map<string, string> fa; map<string, int> weight, ret, sum, ans; string find(string x){ string y = x; while(x != fa[x]) x = fa[x]; if(weight

2022-01-27 23:36:35 196

原创 1030 Travel Plan (30 分)

1030 Travel Plan (30 分) 思路有空更新 #include <iostream> #include <cstring> using namespace std; const int inf = 0x3f3f3f3f; int map[550][550], vis[550], dis[550], path[550]; int a[550][550], sum[550]; int n, m, S, D; void dijkstra(int s){ memset(di

2022-01-27 23:35:44 339

原创 1022 Digital Library (30 分)

1022 Digital Library (30 分) 思路有空更新 #include <iostream> #include <sstream> #include <algorithm> #include <vector> #include <map> using namespace std; map<string, vector<string> > m; int main() { int n, M, x; strin

2022-01-27 23:34:23 70

原创 7-4 Helping the Couriers (30 分)

7-4 Helping the Couriers (30 分) Gao recently took a part time job as a courier(快递员). Every time as he picks up N packages from the distribution center, he would always try to find the best way to deliver those packages so that he can finish this round as q

2021-12-23 17:21:03 590

原创 7-3 Size of Military Unit (25 分)

7-3 Size of Military Unit (25 分) 记忆化搜索,每次搜存每个点 #include <iostream> #include <vector> using namespace std; vector<int> v[100100]; int ans[100100]; int dfs(int x) { for(int i = 0; i < v[x].size(); ++i) ans[x] += dfs(v[x][i]); return

2021-12-23 16:45:42 873

原创 7-2 Rank a Linked List (25 分)

7-2 Rank a Linked List (25 分) 找到-1的点,从后往前找就行 #include <iostream> #include <map> using namespace std; int a[100100]; map<int, int> m; int main() { int n, root, ret = 1, x; cin >> n; for(int i = 0; i < n; ++i) { cin >> x

2021-12-23 16:39:43 2442 1

空空如也

空空如也

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

TA关注的人

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