题意:给定一些木棒,木棒两端都涂上颜色,不同木棒相接的一边必须是相同的颜色,
求是否能将木棒首尾相接,连成一条直线.
分析:可以用欧拉路的思想来解,将木棒的每一端都看成一个结点
由图论知识可以知道,无向图存在欧拉路的充要条件为:
① 图是连通的;
② 所有节点的度为偶数,或者有且只有两个度为奇数的结点。...
分类:
其他好文 时间:
2014-10-30 13:34:24
阅读次数:
211
题目链接:poj 2513 Colored Sticks
题目大意:有N个木棍,每根木棍两端被涂上颜色,现在给定每个木棍两端的颜色,不同木棍之间拼接需要颜色相同的
端才可以,问最后能否将N个木棍拼接在一起。
解题思路:欧拉通路+并查集+字典树。欧拉通路,每个节点的统计度,度为奇数的点不能超过2个。并查集,判断节点
是否完全联通。字典树,映射颜色。
#include
...
分类:
其他好文 时间:
2014-10-30 00:29:11
阅读次数:
158
LeetCode - Sort ColorsGiven an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will...
分类:
其他好文 时间:
2014-10-29 15:00:37
阅读次数:
162
Sort ColorsGiven an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the ...
分类:
其他好文 时间:
2014-10-24 18:38:49
阅读次数:
258
Colored Sticks
Time Limit: 5000MS
Memory Limit: 128000K
Total Submissions: 31015
Accepted: 8180
Description
You are given a bunch of wooden sticks. Each endpoint of e...
分类:
其他好文 时间:
2014-10-22 01:09:19
阅读次数:
193
题目描述:Given an array withnobjects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order re...
分类:
其他好文 时间:
2014-10-21 00:43:54
阅读次数:
304
【题目】
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.
Here, we will use the int...
分类:
其他好文 时间:
2014-10-13 22:00:39
阅读次数:
179
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.
Here, we will use the integers ...
分类:
其他好文 时间:
2014-10-12 20:20:18
阅读次数:
159
Origami Box Start with a square 6" x 6" (15cm x 15cm) origami paper. Flip the sheet so that the colored side is face down. Now make two mountain folds...
分类:
其他好文 时间:
2014-10-09 17:42:58
阅读次数:
369
Given an array withnobjects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, .....
分类:
其他好文 时间:
2014-10-06 15:15:50
阅读次数:
146