Time Limit: 5000MS   Memory Limit: 128000K Total Submissions: 27704   Accepted: 7336 Description You are given a bunch of wooden sticks. Each endpoint of each stick is colored with some color. Is it possible to align the sticks in a straight line suc…
题目:http://poj.org/problem?id=2513 参考博客:http://blog.csdn.net/lyy289065406/article/details/6647445 http://www.cnblogs.com/LK1994/p/3263462.html #include <iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<stac…
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 possible to align the sticks in a straight line such that the colors of the endpoints that touch are of t…
题目链接:http://poj.org/problem?id=2513 题解:通过这题了解了字典树.用字典树存储颜色,并给颜色编上序号.这题为典型的欧拉回路问题:将每种颜色当成一个点.首先通过并查集判断是否为连通图,再检验是否符合欧拉回路的特点.不过题目有一点很奇怪,在并查集中,若图为连通,不是有且仅有一个点的fa[]等于它自己吗,即类似于根节点?为什么会出现有0个的情况,这一点搞不懂. 判断欧拉路是否存在的方法: 有向图:图连通,有一个顶点出度大入度1,有一个顶点入度大出度1,其余都是出度=入…
Colored Sticks Time Limit: 5000MS   Memory Limit: 128000K Total Submissions: 40043   Accepted: 10406 Description You are given a bunch of wooden sticks. Each endpoint of each stick is colored with some color. Is it possible to align the sticks in a s…
经典好题,自己不知道哪里错了交上去是RE,可能是数组开的不好吧,字典树老碰到这种问题.. 先马上别人的代码,有空对拍看看 #include <cstdio> #include <cstring> ; int fa[MAX], d[MAX], cnt; struct Trie { ]; int jud[MAX]; Trie() { sz = ; memset(t[], -, sizeof(t)); jud[] = ; } void clear() { sz = ; memset(t[…
题意:俩头带有颜色的木棒,要求按颜色同的首尾相连,可能否? 思路:棒子本身是一条边,以俩端为顶点(同颜色共点),即求是否有无向图欧拉路(每条棒子只有一根, 边只能用一次,用一次边即选一次棒子). 先判断图是否连通,并查集判断即可,有fa[i]==i的,表示"根",连通图只能有一个这样根,大于1不连通. 在判断欧了图是否存在,度权为偶数或者只有2俩奇数为欧拉图,否则不是. 未1a原因: 1,有一段时间没写并查集了,这次并查集,并的时候也写错!SB啊! 2. 特殊情况,0个点的时候输出可能…
Description You are given a bunch of wooden sticks. Each endpoint of each stick is colored with some color. Is it possible to align the sticks in a straight line such that the colors of the endpoints that touch are of the same color? Input Input is a…
题意:给出很多很多很多很多个棒子 左右各有颜色(给出的是单词) 相同颜色的可以接在一起,问是否存在一种 方法可以使得所以棒子连在一起 思路:就是一个判欧拉通路的题目,欧拉通路存在:没奇度顶点   或者只有2个奇度顶点 同时要连通   .关键在于给颜色hash和 判断连通性   hash用字典树  连通用并查集 #include<cstdio> #include<iostream> #include<cstring> using namespace std; +; str…
考试的时候用了两个树状数组去优化,暴力修改,树状数组维护修改后区间差值还有最终求和,最后骗了40分.. 这道题有好多种做法,求和好说,最主要的是开方.这道题过的关键就是掌握一点:在数据范围内,最多开方五六次就会变成1,这样以后再修改就不用修改了. ①  线段树打标记 ②  分块打标记 ③  树状数组+并查集 因为我考试的时候用的树状数组,所以直接打的第三种,相对来说代码量也少一些. 思路:开始时父亲都指向自己,如果变成1,就把父亲指向下一个位置即可.修改的时候相当于跳着修改.代码当中会有注解.…