- 博客(102)
- 资源 (5)
- 问答 (1)
- 收藏
- 关注
原创 1147 Heaps (30 point(s))
题解堆的判定。#include<cstdio>using namespace std;const int MAXN = 1e3 + 10;int n, m;int t[MAXN];void getpost(int root) { if(root > n) return; getpost(root<<1); getpost(root<&l...
2019-02-20 18:32:39 405 2
原创 1146 Topological Order (25 point(s))
题解拓扑排序。#include<iostream>#include<cstring>#include<vector>using namespace std;const int MAXN = 1e3 + 10;vector<int> e[MAXN];int in[MAXN], t[MAXN];int n, m, a, b, ...
2019-02-20 17:57:09 193
原创 1145 Hashing - Average Search Time (25 point(s))
题解解决冲突应该msize / 2就可以了。没有必要msize。 #include<iostream>#include<cstdio>#include<vector>#include<cmath>using namespace std;bool isPrime(int x) { if(x < 2) return fal...
2019-02-20 17:38:24 221
原创 1144 The Missing Number (20 point(s))
#include<cstdio>#include<iostream>#include<unordered_map>using namespace std;unordered_map<int, bool> have;int n, x;int main() { scanf("%d", &n); for(int i = 0; ...
2019-02-19 12:23:02 200
原创 1143 Lowest Common Ancestor (30 point(s))
题解利用BST的性质即可。#include<iostream>#include<cstdio>#include<vector>#include<unordered_map>using namespace std;int w, u, v, n, m;unordered_map<int, bool> have;in...
2019-02-18 18:54:06 251
原创 1142 Maximal Clique (25 point(s))
题解最大点集判断。 #include<iostream>#include<cstdio>#include<cstring>using namespace std;const int MAXN = 210;int e[MAXN][MAXN];int nv, ne, m, k, a, b;int have[MAXN], v[MAXN];...
2019-02-18 18:51:56 175
原创 1141 PAT Ranking of Institutions (25 point(s))
题解unordered_map #include<iostream>#include<cstdio>#include<unordered_map>#include<algorithm>#include<vector>using namespace std;struct node { string school; ...
2019-02-18 18:49:58 220
原创 1140 Look-and-say Sequence (20 point(s))
#include<iostream>#include<cstdio>#include<string>using namespace std;string res;int n;int main() { cin >> res >> n; for(int i = 0; i < n - 1; ++i) { char...
2019-02-18 18:45:56 202
原创 1139 First Contact (30 point(s))
题解技巧性在于交际网络中,只录入同性关系。#include<iostream>#include<cstdio>#include<map>#include<algorithm>#include<vector>using namespace std;const int MAXN = 1e4;struct node ...
2019-02-17 17:42:59 311
原创 1138 Postorder Traversal (25 point(s))
题解树的遍历。#include<cstdio>#include<iostream>#include<vector>using namespace std;vector<int> pre, in, post;void getpost(int l, int r, int root) { if(l > r) return;...
2019-02-17 17:09:18 258
原创 1137 Final Grading (25 point(s))
题解STL应用。#include<iostream>#include<cstdio>#include<cmath>#include<algorithm>#include<map>using namespace std;const int MAXN = 1e4 + 10;struct node { string...
2019-02-17 17:07:37 183
原创 1136 A Delayed Palindrome (20 point(s))
题解回文串简单判断。#include<iostream>#include<string>#include<cstdio>#include<algorithm>using namespace std;bool isPalin(string a) { string b = a; reverse(a.begin(), a.end(...
2019-02-17 13:01:09 335
原创 1135 Is It A Red-Black Tree (30 point(s))
题解红黑树性质的判断。#include<iostream>#include<cstdio>#include<vector>#include<algorithm>using namespace std;vector<int> pre;int n, k;struct node { node *l, *r; int ...
2019-02-17 12:56:00 303
原创 1131 Subway Map (30 point(s))
题解spfa可以解,但是比较麻烦。最好还是暴力dfs.以下题解少考虑了情况,Pat给的测试数据还是太少了,所以过了。#include<iostream>#include<cstdio>#include<vector>#include<algorithm>#include<queue>using namespac...
2019-02-16 21:39:09 351
原创 1134 Vertex Cover (25 point(s))
#include<iostream>#include<cstdio>#include<algorithm>#include<vector>using namespace std;int n, m, k, a, b, nv;vector<vector<int>> e;int main() { scanf("...
2019-02-16 18:36:21 195
原创 1133 Splitting A Linked List (25 point(s))
#include<iostream>#include<cstdio>#include<vector>using namespace std;const int MAXN = 1e5;struct node { int data, nex;}t[MAXN]; vector<int> res[3];int n, k, x, fir...
2019-02-16 18:35:14 195
原创 1132 Cut Integer (20 point(s))
#include<cstdio>#include<iostream> #include<string>#include<algorithm>using namespace std; typedef long long ll;ll n, a, b, c;string s;int main() { scanf("%lld", &a...
2019-02-16 18:34:05 197
原创 1130 Infix Expression (25 point(s))
题解树的遍历,输出树的中序序列。#include<iostream>#include<cstdio>#include<string>#include<algorithm>#include<vector> using namespace std;const int MAXN = 22;int root, n; ...
2019-02-16 13:17:16 185
原创 1129 Recommendation System (25 point(s))
题解set中erase函数的使用。#include<iostream>#include<set>#include<cstdio>using namespace std;const int MAXN = 5e4 + 10;struct node { int item, cnt; bool operator < (const nod...
2019-02-16 13:10:17 201
原创 1128 N Queens Puzzle (20 point(s))
题解八皇后问题。#include<iostream>#include<cstdio>using namespace std;const int MAXN = 1e3 + 10;int a[MAXN];int k, n;int main() { scanf("%d", &k); for(int i = 0; i < k; ++i) ...
2019-02-16 12:36:03 188
原创 1126 Eulerian Path (25 point(s))
#include<iostream>#include<cstdio>#include<queue>#include<vector>using namespace std;const int MAXN = 510;bool vis[MAXN];vector<vector<int>> e; int n, ev...
2019-02-15 19:12:24 179
原创 1127 ZigZagging on a Tree (30 point(s))
题解树的遍历变形。#include<iostream>#include<cstdio>#include<vector>using namespace std;int n;vector<int> in, post;vector<vector<int>> level;void getlevel(int ...
2019-02-15 18:06:55 196 1
原创 1125 Chain the Ropes (25 point(s))
#include<cstdio>#include<iostream>#include<vector>#include<algorithm>using namespace std;vector<int> t;int n, res;int main() { scanf("%d", &n); t.resize(n)..
2019-02-15 18:05:21 191 1
原创 1124 Raffle for Weibo Followers (20 point(s))
#include<iostream>#include<cstdio>#include<string>#include<map>using namespace std;int m, n, s, flag;string name;map<string, bool> have;int main() { scanf("%d...
2019-02-15 18:04:11 234 1
原创 1122 Hamiltonian Cycle (25 point(s))
题解哈密顿回路。由指定的起点前往指定的终点,途中经过所有其他节点且只经过一次。在图论中是指含有哈密顿回路的图,闭合的哈密顿路径称作哈密顿回路,含有图中所有顶点的路径称作哈密顿路径。判断给出方案的连通性与环路判断。#include<cstdio>#include<iostream>#include<vector>using namespac...
2019-02-15 16:20:01 185
原创 1123 Is It a Complete AVL Tree (30 point(s))
题解完全AVL树。考察AVL树的建树与完全性判断。 #include<cstdio>#include<iostream>#include<algorithm>#include<queue>using namespace std;struct node { node *l, *r; int v;};node* rot...
2019-02-15 16:17:39 192 1
原创 1121 Damn Single (25 point(s))
#include<iostream>#include<set>#include<vector>using namespace std;int main(){ int n, a, b, m; scanf("%d", &n); vector<int> couple(100000, -1); for(int i = 0; i ...
2019-02-15 10:25:03 185
原创 1120 Friend Numbers (20 point(s))
题解模拟题。#include<iostream>#include<cstdio>#include<set>using namespace std;set<int> res;int getsum(int x) { int ret = 0; while(x) ret += x % 10, x /= 10; return r...
2019-02-15 10:22:54 179
原创 1119 Pre- and Post-order Traversals (30 point(s))
题解怎么确定是否有唯一的树, 其实就是看除了叶子以外的每个节点是否都有两个儿子, 因为有一个儿子的话,它既可以是左儿子也可以是右儿子。当不唯一时,全部当右儿子看待。#include<iostream>#include<cstdio>#include<vector>using namespace std;vector<int>...
2019-02-12 18:24:41 276
原创 1118 Birds in Forest (25 point(s))
题解并查集。#include<cstdio>#include<iostream>#include<algorithm>using namespace std;const int MAXN = 1e4 + 10;int father[MAXN], book[MAXN], cnt[MAXN];int find(int x) { retur...
2019-02-12 17:40:59 182
原创 1117 Eddington Number (25 point(s))
题解题意比较难理解。假设骑车E天,则这E天内每天所骑行距离必须大于E。(E是动态变化的)#include<iostream>#include<cstdio>#include<vector>#include<algorithm>using namespace std;int n;int main() { scanf("%...
2019-02-12 17:39:16 220
原创 1116 Come on! Let's C (20 point(s))
#include<iostream>#include<map>#include<cstdio>#include<cmath>using namespace std;const int MAXN = 1e5;int ran[MAXN];map<int, bool> have;int n, k, x;bool ispr...
2019-02-12 17:35:59 156
原创 1115 Counting Nodes in a BST (30 point(s))
题解BST建树。#include<iostream>#include<cstdio>using namespace std;const int MAXN = 1e3 + 10;int level[MAXN];int maxdepth, n;struct node { node *l, *r; int v;}; node* build(int...
2019-02-11 18:03:25 180
原创 1114 Family Property (25 point(s))
题解模拟题。#include<iostream>#include<cstdio>#include<algorithm>using namespace std;const int MAXN = 1e5;struct node { int id, fat, mot, num, people; int child[8]; double a...
2019-02-11 17:48:22 235
原创 1113 Integer Set Partition (25 point(s))
#include<iostream>#include<cstdio>#include<algorithm>#include<vector>using namespace std;int n, sum, half;int main() { scanf("%d", &n); vector<int> res(n);..
2019-02-11 11:18:24 179
原创 1112 Stucked Keyboard (20 point(s))
题解加边界条件减少判断。。。此题在字符串尾部加“#”。通过改变输入来减少考虑情况。 类似manacher算法在首部加$符号、尾部加\0.#include<iostream>#include<map>#include<cstdio>#include<vector>using namespace std;int k, cnt ...
2019-02-11 11:07:17 283
原创 1111 Online Map (30 point(s))
题解dijkstra模板题。#include<iostream>#include<vector>#include<algorithm>using namespace std;const int INF = 0x3f3f3f3f;const int MAXN = 510;vector<int> dispath, Timepat...
2019-02-10 17:09:10 257
原创 1110 Complete Binary Tree (25 point(s))
题解完全二叉树。 #include<iostream>#include<cstdio>#include<queue>#include<vector>#include<string>#include<algorithm>using namespace std;struct node { int ...
2019-02-10 15:42:35 217
原创 1109 Group Photo (25 point(s))
题解模拟题。#include<iostream>#include<cstdio>#include<string>#include<vector>#include<algorithm>using namespace std;int n, k, m, cnt;struct node { string name;...
2019-02-10 15:18:27 197
原创 sscanf 、sprintf的常见用法
sprintf功能把格式化的数据写入某个字符串缓冲区。原型int sprintf( char *buffer, const char *format, [ argument] … );参数列表buffer:char型指针,指向将要写入的字符串的缓冲区。format:格式化字符串。[argument]...:可选参数,可以是任何类型的数据。返回值...
2019-02-10 14:04:22 190
ACM常用模板
2018-04-21
pat乙级1070代码有测试点过不了,求教
2017-03-04
TA创建的收藏夹 TA关注的收藏夹
TA关注的人