- 博客(18)
- 资源 (2)
- 收藏
- 关注
原创 PAT--1092. To Buy or Not to Buy
problem link题解#include <iostream>#include <algorithm>#include <cstdio>#include <map>#include <string>using namespace std;int hash_a[128];int hash_b[128];int main(){#ifndef ONLINE_JUDGEfreopen("
2016-11-30 15:13:28 245
原创 PAT--1097. Deduplication on a Linked List
DescriptionGiven a singly linked list L with integer keys, you are supposed to remove the nodes with duplicated absolute values of the keys. That is, for each value K, only the first node of which the
2016-11-28 23:30:27 434
原创 PAT--1096. Consecutive Factors
Descriptionmong all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 3*5*6*7, where 5, 6, and 7 are the three consecutive numbers. N
2016-11-27 19:41:48 299
原创 PAT--1100. Mars Numbers
problem link题解实质上还是10进制和13进制的相互转换。#include <iostream>#include <cstdio>#include <algorithm>#include <string>#include <cstdlib>#include <map>#include <vector>#include <cctype>#include <sstream>u
2016-11-26 13:07:13 326
原创 poj--1703 Find them, Catch them(并查集)
problem link题解对于 D a b,a和b属于不同的帮派,如果a属于帮派A,那么a + n属于帮派B,同理,b也是如此。 因此,并查集中元素的个数是2n,每次合并就是Union(a, b + n) 和 Union(a + n, b) 这实际上是保留了所有的可能性,因为只知道a和b不在同一个集合里,不能确定到底是属于哪个集合。#include <iostream>#include <a
2016-11-25 23:32:22 389
原创 poj--3349 Snowflake Snow Snowflakes(哈希)
problem link题解判断是否有两片雪花相同。。 对每一雪花的六个值求和进行哈希,这样判断两片雪花相同就只需要在相同的哈希值下进行。#include <iostream>#include <cstdio>#include <algorithm>#include <vector>using namespace std;const int maxn = 100000 + 5;const
2016-11-24 23:28:19 455
原创 PAT--1114. Family Property(并查集)
problem link题解对每个人的id以及其双亲 和孩子id建立并查集。#include <iostream>#include <cstdio>#include <algorithm>#include <queue>#include <vector>#include <stack>using namespace std;const int maxn = 10005;struct P
2016-11-23 17:15:46 405
原创 PAT--1106. Lowest Price in Supply Chain
problem link题解题目大意:根节点处有一货物,价值为p,每向下一层价值增加r,求叶子结点的最小价值,以及具有最小价值的叶节点的个数。dfs遍历一下。#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <vector>using namespace std;const in
2016-11-22 21:30:40 367
原创 PAT--1105. Spiral Matrix (25)
DescriptionThis time your job is to fill a sequence of N positive integers into a spiral matrix in non-increasing order. A spiral matrix is filled in from the first element at the upper-left corner, th
2016-11-21 23:20:13 434
原创 PAT--1103. Integer Factorization (dfs)
problem link题解求整数N的k-p分解,预处理出小于 N 的 (ni)p(n_i)^p,然后深度搜索。#include <iostream>#include <cstdio>#include <vector>#include <algorithm>#include <cstring>#include <cmath>#include <string>using namespac
2016-11-20 22:09:04 472
原创 PAT--1107. Social Clusters(并查集)
problem link题解并查集,计算集合数以及每个集合的大小。#include <iostream>#include <cstdio>#include <algorithm>#include <vector>#include <map>using namespace std;const int maxn = 1000 + 5;int p[maxn];int n;int tot;
2016-11-20 16:22:50 326
原创 PAT--1102. Invert a Binary Tree
problem link题解反转一棵二叉树,然后层序遍历和中序遍历。trick: 输入的时候左右节点互换,就实现了反转。#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <queue>#include <algorithm>#include <vector>using name
2016-11-20 00:01:35 301
原创 poj--1100 Dreisam Equations(dfs)
Problem Link题解在等式中重新放置 + - * 以便构造一个有效的等式。对于每个可以放置运算符的位置,都有三种选择,因此解空间是一棵完全三叉树,回溯搜索O(n3)O(n^3)。需要注意存在冗余括号的情况。#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <cctype
2016-11-08 21:19:35 1088
原创 PAT--1101. Quick Sort
Problem Link题解从左向右维护一个最大值,从右向左维护一个最小值。 分别扫描一遍,可以得出a[i]和左右两边比较的信息。#include <iostream>#include <climits>#include <algorithm>#include <cstdio>using namespace std;const int maxn = 100000 + 5;int a[ma
2016-11-07 23:06:08 303
原创 PAT--1109. Group Photo
link to problem题解模拟怎么排队拍照。 deque模拟向左向右入队..#include <iostream>#include <string>#include <vector>#include <deque>#include <cstdio>#include <algorithm>using namespace std;struct Student{ string
2016-11-07 22:15:27 373
原创 codeforces--733B. Parade
problem题解题意抽象一下,有两个数组 l[...],r[...]l[...], r[...],可以从中选择某一l[i],r[i]l[i], r[i]交换,也可以不选,求使|L−R||L - R|最小的i. L=∑ni=1l[i]L = \sum_{i=1}^{n}l[i], R=∑ni=1r[i]R = \sum_{i=1}^{n}r[i].#include <bits/stdc++.h>
2016-11-05 17:02:05 542
原创 codeforces--733A. Grasshopper And the String
problem题解AEIOUY是可以下脚跳的地方,求一步最少需跨多少个字母。 * 首尾加上’A’(AEIOUY中任意一个),计算相邻的两个相距的最长距离。#include <bits/stdc++.h>using namespace std;string s;int main(){ string letter = "AEIOUY"; cin >> s; int ans
2016-11-03 23:07:54 455
原创 PAT--1104. Sum of Number Segments
link to problem题解第i个数累加的次数为 i * (n - i + 1).#include <iostream>#include <algorithm>#include <cstdio>using namespace std;const int maxn = 100000 + 5;double a[maxn];int n;int main(){#ifndef ONLINE_
2016-11-03 21:02:05 333
蓝桥杯2014年C语言真题
2015-02-02
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人