
数据结构
文章平均质量分 62
Terry__J
这个作者很懒,什么都没留下…
展开
-
usaco Broken Necklace字符串
<br /> <br />Broken Necklace<br />破碎的项链<br />译 by timgreen<br />你有一条由N个红色的,白色的,或蓝色的珠子组成的项链(3<=N<=350),珠子是随意安排的。 这里是 n=29的二个例子: 1 2 1 2 r b b r b r r b r原创 2011-05-11 01:27:00 · 815 阅读 · 0 评论 -
hdoj 3038How Many Answers Are Wrong 并查集
思路:以区间标号大的为根建树,sum[a] 表示从a+1开始到当前根节点的和。剩下的就是并查集的操作了。#include #include #include using namespace std;const int N = 200100;int p[N], sum[N];int ans, n, m;void init() { int i; ans = 0原创 2012-04-15 12:13:41 · 841 阅读 · 0 评论 -
hdoj 4006 The kth great number
思路:用优先队列维护前k个大的元素,每次查询时,队首元素即为所求答案。#include #include #include #include #include using namespace std;priority_queue, greater > q;int main(){ int n, k; while (scanf("%d %d", &n, &k)原创 2012-04-12 17:26:36 · 643 阅读 · 0 评论 -
hdoj 4198 Quick out of the Harbour 优先队列 + bfs
思路:对于普通迷宫求解,bfs可以到到唯一解,也是最优解。但对于不同点具有不同权值的地图就不一定了,很可能最优值会被pass掉,但使用优先队列的话,访问当前的点总是以前一个优先权最高的点访问的。#include #include #include #include #include using namespace std;const int N = 509;struct n原创 2012-04-07 18:41:38 · 863 阅读 · 0 评论 -
ural 1654 Cipher Message
思路:数据结构的题目,模拟栈的操作:若栈为空,则将原串的字符入栈,若栈不为空且栈顶元素与原串中的相同,则出栈;新入栈的元素需同之前的比较,若相同都出栈。#include #include #include #include using namespace std;const int N = 250009;char s[N];char ans[N];int main(voi原创 2012-04-02 09:30:57 · 1051 阅读 · 0 评论 -
ural 1306. Sequence Median
思路:此题不能存储所有元素,否则会MLE,想到用优先队列(默认值大的优先级高),存储一半,剩下的一半依次和队首比较,若小于队首,则将队首元素出队,新元素入队。最后,若n为奇数,队首元素即为中间值;n为偶数,队列前两个的平均值为答案。#include #include #include #include #include using namespace std;typedef原创 2012-04-02 14:57:19 · 1175 阅读 · 0 评论 -
usaco Greedy Gift Givers 字符串
<br />20:00:282011-05-06<br />题意:有中文网页,不解释.<br />思路:正常思维,模拟.<br />注意:取平均值时不能除零.<br />代码:<br />#include <iostream>#include <algorithm>#include <cstring>#include <cstdio>using namespace std;int n;char name[11][20];int search(char s[]){ int原创 2011-05-06 20:00:00 · 679 阅读 · 0 评论 -
uva 10252Common Permutation
题意:给定两个字符串a,b,求a,b的最长公共子串,按字典顺序输出.思路:由于计数的只有小写字母,可以使用int数组将字符串的字符映射到数组上.通过比较两数组是否均含有某一字符,顺序输出。代码:#include #include #include using namespace std;char a[1010],b[1010];int la[27],lb[27];int min(int n, int m){ return n原创 2011-05-04 19:50:00 · 793 阅读 · 0 评论 -
poj 1989 The Cow Lineup 数组
<br />题意:给定牛的类型的一组序列(类型范围1-k),其子序列有很多,求原序列不存在的最短子序列.例如: k = 5 类型序列 1 5 3 2 5 1 3 4 4 2 5 1 2 3. 长度为一的子序列1 2 3 4 5 原序列都有,长度为二的子序列也全有,当长度为3时, <br />2 2 4未出现.所以输出最短长度为3.<br />思路:<br />用一变量 ans 表示当前验证子序列长度,用一bool数组标识某类型是否被访问.<br />还有一点需要理解:只有当某一长度子序列的最后一种可能存原创 2011-05-03 22:33:00 · 928 阅读 · 0 评论 -
poj 1611 The Suspects 并查集
<br /> The SuspectsTime Limit: 1000MS Memory Limit: 20000KTotal Submissions: 10873 Accepted: 5158<br />DescriptionSevere acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To原创 2011-05-03 14:56:00 · 580 阅读 · 0 评论 -
poj 1002 字符串
<br />题意:电话拨号有不同的形式,其中的一种映射:<br />A, B, and C map to 2 <br />D, E, and F map to 3 <br />G, H, and I map to 4 <br />J, K, and L map to 5 <br />M, N, and O map to 6 <br />P, R, and S map to 7 <br />T, U, and V map to 8 <br />W, X, and Y map to 9 <br />对于输入的电原创 2011-05-04 12:51:00 · 520 阅读 · 0 评论 -
poj 3067 Japan
<br />题意:日本东海岸有n个城市,西海岸有m个城市,现在要修建k条高铁连接东海岸的城市u和西海岸的城市v。问这k条高铁总共有多少个交点。<br />思路:树状数组。(本人未理解,装载供以后学习)<br />代码:<br />#include <iostream>#include <algorithm>#include <cstdio>using namespace std;const int MAX = 1009;typedef long long ll;ll arr[MAX]转载 2011-05-02 19:29:00 · 583 阅读 · 0 评论 -
POJ 3510 string
<br />题意: 对某些特定字符转换<br />思路:优先判断特殊字符的转换,最后判断相应字符是否输出.<br />注意:结束符 "EOF"可以出现在任意位置.<br />代码:<br />#include <cstdio>#include <cstring>#include <iostream>using namespace std;int main(void){ char s[90]; char tmp[] = "floyd"; while(true) { g原创 2011-05-22 13:27:00 · 798 阅读 · 0 评论 -
POJ 1028 字符串
<br />题意:<br />浏览网页,这里有几种操作:<br />BACK: Push the current page on the top of the forward stack. Pop the page from the top of the backward stack, making it the new current page. If the backward stack is empty, the command is ignored. <br />FORWARD: Push the原创 2011-05-19 12:39:00 · 662 阅读 · 0 评论 -
POJ 1056 字符串
<br />题意:<br />对于输入的一串字符串,判断是否其中的的一个是另一个的前缀码<br />思路:数据量很小,对串排序后,枚举所有串两两表较就可以了<br />代码:<br />#include <iostream>#include <cstdio>#include <cstring>using namespace std;char str[15][15];int cmp(const void *a, const void *b){ return strcmp((char原创 2011-05-18 00:13:00 · 970 阅读 · 0 评论 -
hdu 1671 Phone List 字典树
题意:判断是否有一电话号码是另一个的前缀。思路:建立字典树, 参考维基百科:http://zh.wikipedia.org/wiki/Trie需要注意的是最后释放内存,否则会MLE。#include #include #include #include using namespace std;const int N = 10;struct Trie { bool原创 2012-05-07 12:27:23 · 874 阅读 · 0 评论