POJ1639:Picnic Planning
摘要:——problem:度限制生成树——solution:Kruskal算法框架:1.先求出最小m度限制生成树;2.由最小m度限制生成树得到最小m+1度限制生成树;3.当dT(v0)=k时停止(即当V0的度为k的时候停止);第一步:求解最小m度限制生成树:原图中去掉和V0相连的所有边,得到m个连通分量,而这m个连通分量必须通过v0来连接,所以,在图G的所有生成树中dT(v0)≥m。也就是说,当k<m时,问题无解。对每个连通分量求一次最小生成树,对于每个连通分量V’,求一点v1,v1∈V',且ω(v0,v1)=min{ω(v0,v')|v'∈V'},则该连通分量
阅读全文
posted @
2011-03-26 21:43
风也轻云也淡
阅读(274)
推荐(0)
HDU3070:Counting spanning trees
摘要:——problem:有度限制的生成树个数——solution:Cayley公式,Prüfer编码,递推Cayley公式是:一个完全图K_n有n^(n-2)棵生成树,换句话说n个节点的带标号的无根树有n^(n-2)个。Cayley公式的一个非常简单的证明,证明依赖于Prüfer编码,它是对带标号无根树的一种编码方式:给定一棵带标号的无根树,找出编号最小的叶子节点,写下与它相邻的节点的编号,然后删掉这个叶子节点。反复执行这个操作直到只剩两个节点为止。由于节点数n>2的树总存在叶子节点,因此一棵n个节点的无根树唯一地对应了一个长度为n-2的数列,数列中的每个数都在1到n的范
阅读全文
posted @
2011-03-26 21:40
风也轻云也淡
阅读(457)
推荐(0)
ZOJ3223:Journey to the Center of the Earth
摘要:——problem:n个点,边有两种,一种是普通的路,一种是近道,求在规定时间内从起点到终点用的最少的近道数是多少。——solution:二维DIJKSTRA一开始犯傻了,二分用的近道数,看能不能再规定时间内到达……结果超时。其实直接求DIST[I][J]就好了,然后找个J最小的且在规定时间的的J就是答案了。结果还是超时……感觉50*100*100*100应该不会超……看了下题解,有个小优化,Limit初始为近道数。每次到终点时记录下用的近道数,如果比LIMIT小就更新,这样如果当前状态用的近道数比limit还大的话就直接忽略。View Code 1 #include<stdio.h&g
阅读全文
posted @
2011-03-25 22:06
风也轻云也淡
阅读(182)
推荐(0)
POJ3072:Robot
摘要:——url:——problem:二维平面上有N个点,求从1到N的最短时间,转向需要时间,每度一秒。——solution:二维DIJKSTRA,DIST[I][J]表示起点到I的最短时间,I的前驱为J,用来计算转向时间。注意:1、转向角度<=180度。2、用atan2比atan好,atan2值域范围-pi到pi。3、计算转向角: 例如:由P1经过P2到P3 angle=fabs(atan2(p2.y-p1.y,p2.x-p1.x)【P2-P1向量的方向角】-atan2(p3.y-p2.y,p3.x-p2.x)【P3-P2向量的方向角】)———————————————————————————
阅读全文
posted @
2011-03-20 21:52
风也轻云也淡
阅读(265)
推荐(0)
POJ3662:Telephone Lines
摘要:URL:http://poj.org/problem?id=3662——problem:一个无向图有n个点, p条边, 每边有花费, 可以任意指定有k条边免费, 现要求选择若干条边构成顶点1到顶点n的一条路径, 使得路径上边权最大值(不包括免费边)最小.——solution:二分答案,最短路假设A是可行解,即路径上边权最大值为A,则该路径上边权大于A的边一定小于等于K条。若A不是最优解,那么必然B<A,是的路径上边权大于B的边小于等于K。于是我们可以二分答案,得到一个值X,将所有小于等于X的边变为0,大于X的边变为1。做最短路,则1到N的距离就是所用权值大于X边的条数。如果小于等于K,则
阅读全文
posted @
2011-03-19 21:18
风也轻云也淡
阅读(343)
推荐(0)
HDU2992:Hotel booking
摘要:——url:http://acm.hdu.edu.cn/showproblem.php?pid=2992——problem: 有n(≤10000)个地点, m(≤100000)条无向边, 其中有h个地点建有旅馆, 一个人从1出发去n, 此人每天最多走10小时, 然后就要进旅馆休息, 第二天继续走, 直到到达n, 问最少需要预定多少家旅馆(最少需要多少天)可以到达n, 若不能到达则输出-1.——solution: h次Dijkstra求出旅馆间最短路, 然后重新建图再做一次最短路。把起点和终点也当做旅馆。对每个旅馆做次最短路,如果两个旅馆之间的时间<=600,那么这两个旅馆能隔天到达,重新
阅读全文
posted @
2011-03-19 19:31
风也轻云也淡
阅读(455)
推荐(0)
EOJ:National Treasures
摘要:National TreasuresTime Limit: 6000MSMemory Limit: 65536KTotal Submits: 35Accepted: 11DescriptionThe great hall of the national museum has been robbed few times recently. Everyone is now worried about the security of the treasures on display. To help secure the hall, the museum contracted with a priv
阅读全文
posted @
2011-03-03 20:29
风也轻云也淡
阅读(224)
推荐(0)
EOJ:Quick Answer
摘要:Quick AnswerTime Limit: 1000MSMemory Limit: 65536KTotal Submits: 86Accepted: 12DescriptionJoe is fond of computer games. Now, he must solve a puzzling situation. In front of his eyes lies a huge map with fortified towns. His enemy is a very powerful and tricky character who can connect and disconnec
阅读全文
posted @
2011-03-03 20:14
风也轻云也淡
阅读(307)
推荐(0)
EOJ:Mountain Road
摘要:Mountain RoadTime Limit: 10000MSMemory Limit: 65536KTotal Submits: 21Accepted: 8DescriptionIn the Franconian Switzerland, there is a narrow mountain road. With only a single lane, this is a bottleneck for two-way traffic. Your job is to schedule incoming cars at both ends so that the last car leaves
阅读全文
posted @
2011-02-17 19:55
风也轻云也淡
阅读(207)
推荐(0)
EOJ:Circle Artwork
摘要:Circle ArtworkTime Limit: 1000MSMemory Limit: 65536KTotal Submits: 48Accepted: 6DescriptionCircle is an ancient and universal symbol of unity, wholeness, infinity, the goddess, and female power. It is referenced frequently in religion and art. In this problem, we act as a modern artist and would lik
阅读全文
posted @
2011-02-17 19:10
风也轻云也淡
阅读(205)
推荐(0)
EOJ:Cleaning Shifts
摘要:Cleaning ShiftsTime Limit: 1000MSMemory Limit: 65536KTotal Submits: 75Accepted: 29DescriptionFarmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now require their barn to be immaculate. Farmer John, the most obliging of farmers, has no choice but hire some
阅读全文
posted @
2011-02-05 21:07
风也轻云也淡
阅读(251)
推荐(0)
EOJ:Electronic Document Security
摘要:Electronic Document SecurityTime Limit: 1000MSMemory Limit: 65536KTotal Submits: 25Accepted: 19DescriptionThe Tyrell corporation uses a state-of-the-art electronic document system that controls all aspects of document creation, viewing, editing, and distribution. Document security is handled viaacce
阅读全文
posted @
2011-02-04 20:30
风也轻云也淡
阅读(123)
推荐(0)
POJ:跳蚤
摘要:跳蚤Time Limit:1000MSMemory Limit:10000KTotal Submissions:4783Accepted:1241DescriptionZ城市居住着很多只跳蚤。在Z城市周六生活频道有一个娱乐节目。一只跳蚤将被请上一个高空钢丝的正中央。钢丝很长,可以看作是无限长。节目主持人会给该跳蚤发一张卡片。卡片上写有N+1个自然数。其中最后一个是M,而前N个数都不超过M,卡片上允许有相同的数字。跳蚤每次可以从卡片上任意选择一个自然数S,然后向左,或向右跳S个单位长度。而他最终的任务是跳到距离他左边一个单位长度的地方,并捡起位于那里的礼物。比如当N=2,M=18时,持有卡片(1
阅读全文
posted @
2011-01-24 21:02
风也轻云也淡
阅读(492)
推荐(0)
EOJ:YO!
摘要:YO!Time Limit: 1000MS Memory Limit: 65536KDescriptionWhile sitting in traffic on I-35 one day, you look up at the pickup in front of you and notice the word "YO" staring back at you from the tailgate....
阅读全文
posted @
2010-08-07 16:18
风也轻云也淡
阅读(165)
推荐(0)
EOJ:Clickomania
摘要:ClickomaniaTime Limit: 5000MS Memory Limit: 65536KDescriptionClickomania is a puzzle in which one starts with a rectangular grid of cells of different colours. In each step, a player selects ("clicks"...
阅读全文
posted @
2010-08-07 15:58
风也轻云也淡
阅读(231)
推荐(0)
EOJ:The Ninja Way
摘要:The Ninja WayTime Limit: 3000MS Memory Limit: 65536KDescriptionAs we all know, Ninjas travel by jumping from treetop to treetop. A clan of Ninjas plans to use N trees to hone their tree hopping skills. They will start at the shortest tree and make N-1 jumps, with each jump taking them to a taller tr
阅读全文
posted @
2010-08-07 15:22
风也轻云也淡
阅读(207)
推荐(0)
EOJ:Museum Guards
摘要:Museum GuardsTime Limit: 5000MS Memory Limit: 65536KTotal Submits: 38 Accepted: 17DescriptionA museum has hired some guards and is trying to build a schedule for them. The museum would like to build a...
阅读全文
posted @
2010-08-05 22:23
风也轻云也淡
阅读(548)
推荐(0)
EOJ:Mosaic
摘要:MosaicTime Limit: 5000MS Memory Limit: 65536KTotal Submits: 13 Accepted: 5DescriptionAn architect wants to decorate one of his buildings with a long, thin mosaic. He has two kinds of tiles available t...
阅读全文
posted @
2010-07-30 21:15
风也轻云也淡
阅读(144)
推荐(0)
ZOJ3358 Green Dam Girl
摘要:Green Dam GirlTime Limit: 1 Second Memory Limit: 65536 KB Green Dam Girl (GDG) became bankrupt recently, and watashi picked her up to his dorm. Some ZJU ICPC team members would like to support her. T...
阅读全文
posted @
2010-07-28 14:56
风也轻云也淡
阅读(305)
推荐(0)
EOJ:Fruit Weights
摘要:Fruit WeightsTime Limit: 1000MS Memory Limit: 65536KTotal Submits: 44 Accepted: 10DescriptionHave you ever thought about comparing the weight of fruits? That’s what you should do in this problem...
阅读全文
posted @
2010-07-28 14:45
风也轻云也淡
阅读(190)
推荐(0)