随笔分类 - 数据结构
摘要:二分的用处太大了,不管是求简单的方程,还是求最优解方面都是不错的解题思想。 只要在线性,顺序或者有序的数据里就可以用二分来找最优的答案,而且时间平均都是O(log2 n)。题目中好像是HDU 4190吧,这题的限时是10000ms,而用二分做才用时1000ms,其优点可想而知。 不过就像《编程珠玑》
阅读全文
摘要:http://poj.org/problem?id=2513 Description You are given a bunch of wooden sticks. Each endpoint of each stick is colored with some color. Is it possi
阅读全文
摘要:http://poj.org/problem?id=3087 Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is perfo
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2833 A friend is like a flower, a rose to be exact, Or maybe like a brand new gate that n
阅读全文
摘要:http://poj.org/problem?id=1182 Description 动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。 现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种。 有人用两种说法对这N个动
阅读全文
摘要:#include #include #include #include using namespace std; typedef struct Node { struct Node *next; int l;//线性表的长度 int data; } Node; Node *head,*head1,*tail,*p,*q; int S,n; void Showmai...
阅读全文
摘要:http://poj.org/problem?id=2528 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have bee
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2806 名字的价值 题目描述 每 个人都有名字,名字都是唯一的不存在重复现象。现在假设名字都是由小写字母组成并且长度不超过10,我们赋予每个名字一个初始价值
阅读全文
摘要:1、 线段树是二叉树,且必定是平衡二叉树,但不一定是完全二叉树。 2、 对于区间[a,b],令mid=(a+b)/2,则其左子树为[a,mid],右子树为[mid+1,b],当a==b时,该区间为线段树的叶子,无需继续往下划分。 3、 线段树虽然不是完全二叉树,但是可以用完全二叉树的方式去构造并存储
阅读全文
摘要:http://poj.org/problem?id=3169 题意: 一堆牛在一条直线上按编号站队,在同一位置可以有多头牛并列站在一起,但编号小的牛所占的位置不能超过编号大的牛所占的位置,这里用d[i]表示编 号为i的牛所处的位置,即要满足d[i]-d[i+1]<=0,同时每两头牛之间有以下两种关系
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1712 分组背包 问题 有N件物品和一个容量为V的背包。第i件物品的费用是c[i],价值是w[i]。这些物品被划分为若干组,每组中的物品互相冲突,最多选一件。求解将哪些物品装入背包可使这些物品的费用总和不超过背包容
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1203 Problem Description Speakless很早就想出国,现在他已经考完了所有需要的考试,准备了所有要准备的材料,于是,便需要去申请学校了。要申请国外的任何大学,你都要交纳一定的申请费用,这可
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1171 题意:给出每个物体的价值和物体的数量,如何分使得A,B所得价值最接近并且A的价值不能小于B 思路:将总和平分后,就是一道多重背包题了
阅读全文
摘要:http://poj.org/problem?id=1014 Description Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that bot
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2191 Problem Description 急!灾区的食物依然短缺!为了挽救灾区同胞的生命,心系灾区同胞的你准备自己采购一些粮食支援灾区,现在假设你一共有资金n元,而市场有m种大米,每种大米都是袋装产品,其价格
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2159 各种背包五(二维费用背包问题) 问题 二维费用的背包问题是指:对于每件物品,具有两种不 同的费用;选择这件物品必须同时付出这两种代价;对于每种代价都有一个可付出的最大值(背包容量)。问怎样选择物品可以得到最
阅读全文
摘要:http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=267#problem/A A - Intervals Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d &
阅读全文
摘要:http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=267#problem/C C - Candies Time Limit:1500MS Memory Limit:131072KB 64bit IO Format:%I64d & %
阅读全文
摘要:http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=267#problem/B B - Is the Information Reliable? Time Limit:3000MS Memory Limit:131072KB 64bi
阅读全文
摘要:差分约束系统有两种方式可以求解,最短路和最长路。当我们把不等式整理成d[a]+w<=d[b]时,我们求最长路。整理成d[a]+w>=d[b]时,我们求最短路。当求最短路时,我们通常要把各点距离初始化为正无穷,求最短路,把各点距离逐渐减小,直到符合所有不等式。也就是开始 各点不符合条件,后来通过减小变
阅读全文