POJ Colored Sticks 2513(字典树+并查集+欧拉回路)

泛微E8流程监控指南:如何用SQL实时追踪审批节点状态? 本文详细介绍了如何利用SQL实时监控泛微E8系统中的审批流程状态,包括核心数据表结构解析、全链路监控SQL实战以及智能预警机制设计。通过数据库直接查询和状态关联分析,帮助企业快速定位卡顿节点,提升流程效率。适用于需要优化OA系统流程管理的企业IT人员和业务主管。 阅读详情

                                                                                                           Colored Sticks
Time Limit: 5000MS Memory Limit: 128000K
Total Submissions: 35376 Accepted: 9264

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 sequence of lines, each line contains two words, separated by spaces, giving the colors of the endpoints of one stick. A word is a sequence of lowercase letters no longer than 10 characters. There is no more than 250000 sticks.

Output

If the sticks can be aligned in the desired way, output a single line saying Possible, otherwise output Impossible.

Sample Input

blue red
red violet
cyan blue
blue magenta
magenta cyan

Sample Output

Possible


题意:给定一些木棒,木棒两端都涂上颜色,求是否能将木棒首尾相接,连成一条直线,要求不同木棒相接的一边必须是相同颜色的。

就是判断欧拉回路,把每个颜色映射成点,用字典树,然后用并查集判断图是否连通,最后判断欧拉回路


本题欧拉回路:图必须是连通的,奇度数点必须是0个或者2个(可以是一条直线或者是圆),这样就是欧拉回路,其他则不是

欧拉回路:无向图连通并且所有结点的度都是偶数,则存在欧拉回路,否则不存在

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <stdio.h>
using namespace std;
int top;
int hao;
int pre[510000];
int du[510000];
struct node
{
    int flag;
    int next[27];
}k[250000*5*2];
int newnode()
{
    k[top].flag=0;
    memset(k[top].next,-1,sizeof(k[top].next));
    return top++;
}
int Insert(int p,char s[])
{
    int l,i,j,t;
    l=strlen(s);
    for(i=0;i<l;i++)
    {
        t=int(s[i]-'a');
        if(k[p].next[t]==-1)
        {
            k[p].next[t]=newnode();
        }
        p=k[p].next[t];
    }
    return k[p].flag=++hao;
}
int query(int p,char s[])
{
    int l,i,j,t;
    l=strlen(s);
    for(i=0;i<l;i++)
    {
        t=int(s[i]-'a');
        if(k[p].next[t]==-1)
        {
            return 0;
        }
        p=k[p].next[t];
    }
    return k[p].flag;
}
int Find(int x)
{
    if(x!=pre[x])
    {
        pre[x]=Find(pre[x]);
    }
    return pre[x];
}
void mix(int a,int b)
{
    a=Find(a);
    b=Find(b);
    if(a!=b)
        pre[a]=b;
}
int main()
{
    top=0;
    hao=0;
    memset(du,0,sizeof(0));
    int ll=newnode();
    int i,j;
    for(i=0;i<500000;i++)
    {
        pre[i]=i;
    }
    int x,y;
    char s1[20],s2[20];
    while(scanf("%s%s",s1,s2)==2)
    {
        x=query(ll,s1);
        if(!x)
        {
            x=Insert(ll,s1);
        }
        y=query(ll,s2);
        if(!y)
        {
            y=Insert(ll,s2);
        }
        du[x]++;
        du[y]++;
        mix(x,y);
    }
    int s=Find(1);//图如果连通,所有点的祖先都是s
    int num=0;
    for(i=1;i<=hao;i++)
    {
        if(du[i]%2==1)
        {
            num++;
        }
        if(num>2)
        {
            printf("Impossible\n");
            return 0;
        }
        if(Find(i)!=s)
        {
            printf("Impossible\n");
            return 0;
        }
    }
    if(num==1)
    {
        printf("Impossible\n");
    }
    else
    {
        printf("Possible\n");
    }

    return 0;
}
















从零搭建Simulink-Adams联合仿真平台:实现电机转速的精准闭环控制 本文详细介绍了从零搭建Simulink-Adams联合仿真平台的完整流程,旨在实现电机转速的精准闭环控制。通过将Simulink的控制算法与Adams的物理模型相结合,构建了一个包含真实机械效应的数字孪生系统。文章涵盖了Adams物理模型构建、接口定义、Simulink控制闭环搭建、PID参数调试以及常见避坑指南,为机电系统仿真提供了实用的工程实践指导。 阅读详情

相关推荐

RGB接口电容触摸屏驱动(二)接口与时序说明

RGB接口电容触摸屏驱动(二)接口与时序说明

杰克拉力船长个人博客 4918

POJ 2513 Colored Sticks(欧拉回路判断+字典树Trie+并查集)

POJ 2513 Colored Sticks(欧拉回路判断+字典树Trie+并查集) http://poj.org/problem?id=2513 题意:给你多个木棍,每个木棍两段涂上颜色,两根木棍只有在相同颜色的一端才能连接,问你能不能使所有木棍都连接成一条直线路. 分析: 将输入的每个颜色看出是图的一个点,然后每条木棍正好是连接了两种颜色的一条边,我们只需要判断这个图中是否存在欧拉道

code 1515

基于555定时器的D类功放设计:从PWM原理到无反馈电路实践

D类功放(数字功放)是一种高效率的音频放大技术,其核心原理是脉冲宽度调制(PWM)。它将输入的模拟音频信号转换为一系列高速开关的脉冲,通过控制功率开关管(如MOSFET)的通断,再经低通滤波器还原放大后的音频。相比传统AB类功放,其转换效率通常超过90%,显著降低了热能损耗。这项技术在追求高能效和小型化的现代音频设备中价值凸显,广泛应用于有源音箱、汽车音响和便携式设备。本文聚焦于一种独特的实现方案:以经典的555定时器芯片为核心,构建一个无整体负反馈的D类功放。通过剖析其PWM调制器、FET电压-电流转换级

weixin_30162121的博客 221

Colored Sticks POJ - 2513 并查集,字典树,欧拉回路

这道题涉及的知识点比较多 前面的博客是为这道题打基础 步入正题,题意是说给出一堆木棒,每根木棒的左边和右边颜色不一样,求能否将所有的木棒按规则连成一条直线,规则是相连的木棒端点处颜色必须一致。 如果可以输出Possible 例如题目中给出的例子(后面的序号是我自己加的) blue red 1 red violet

ices_的博客 485

基于PLC的全自动洗衣机控制系统+控制程序

本设计使用PLC控制系统替换了传统的继电器控制系统,实现了全自动洗衣机在硬件方面的提升,丰富了全自动洗衣机在软件方面的功能,提高了全自动洗衣机的洗衣效率,基本可以满足用户的洗衣需求。

zzzz114231的博客 8955

【Niagara Vykon N4 】物联网学习 03照明控制及照明时间表

3.1 设计思路 3.2逻辑组件添加 ①依据原有控制照明逻辑,打开palette,找到schedule模块,添加BoolenSchedule。 ②打开kitContrl,找到Util,并添加BoolenSwitch。 ③剪切到原有的逻辑线,并进行逻辑连接,如下图。 ④新建BooleanWritable,命名为Switch,设置参数并进行逻辑连接,若下图。 3.3界面设计 ⑤至此完成了逻辑的设...

weixin_45217107的博客 2863

连单词成欧拉路 欧拉回路+字典树+并查集 POJ 2513 Colored Sticks

http://poj.org/problem?id=2513 题意: 给你很多对单词,单词相当于一个点,一对单词相当于一条边,问这么多对的单词能否组成一条欧拉路,要求每条边都要经过。 解析: 题目数据很大,每个单词最多10个字母,据说用map映射会TLE。  所有要改用字典树进行hash。  判断欧拉路径或者回路需要满足两个条件。  图上所有点联通  度数为奇数个的节点

ACM_10000h的专栏 790

机器人控制仿真软件:MATLAB Simulink Control System Toolbox_(1).MATLAB基础知识

MATLAB(Matrix Laboratory)是由MathWorks公司开发的一种高性能数值计算和可视化软件。它广泛应用于科学计算、工程设计、信号处理、控制系统设计、图像处理等领域。强大的矩阵运算能力:MATLAB的核心是矩阵运算,能够高效处理大规模的数值数据。丰富的工具箱:MATLAB提供了大量的工具箱,如Control System Toolbox、Simulink、Signal Processing Toolbox等,这些工具箱覆盖了多个应用领域。易于使用的图形界面。

kkchenjj的博客 904

poj 2513 Colored Sticks 欧拉回路(字典树 +并查集)

此题中涉及三个小算法,这是一个无向图判断欧拉回路, 无向图存在欧拉回路的充要条件 一个无向图存在欧拉回路,当且仅当该图只存在0或2个奇数度数的顶点,且该图是连通图。 有向图存在欧拉回路的充要条件 一个有向图存在欧拉回路,所有顶点的入度等于出度且该图是连通图。 判断度数很简单,当时没想明白怎么判断图示连通的,其实只要判断他们的父节点的个数,只要只有一个父节点,那么此图是

wuhulala的休息室 1335

反应动力学仿真软件:Kintecus_(11).数据输入与输出解析

在反应动力学仿真软件的二次开发中,数据输入与输出解析是至关重要的步骤。正确地解析输入数据和生成输出结果不仅能够确保仿真过程的顺利进行,还可以提高仿真的准确性和效率。本节将详细介绍如何在仿真软件中实现数据输入与输出的解析,包括文件格式、数据结构、解析方法以及实际操作示例。

kkchenjj的博客 757

YOLOv8魔改系列:将CIoU替换成Wise-IoU,飞速涨点

将YOLOv8中CIoU替换成Wise-IoU,实现飞速涨点

qq_66386046的博客 2679

POJ - 2513 Colored Sticks(字典树+并查集+欧拉回路)

题目链接:点击查看 题目大意:给出n个木棍,问若两两相连,最终能否构成一根长直木棍,相连的规则是两个木棍的相接端点的颜色需要保持相同 题目分析:关于这个题目,我们可以将每个木棍视为一条边,每个木棍的两个端点视为两个顶点,问能否相连,我们可以联想到欧拉回路,也就是说必须满足下面的两个条件: 所有的顶点能够构成回路 所有度数为奇数的顶点只能有零个或两个 如此一来题目就简单多了,但还是存在许多细...

Falcon的博客 466

京东运维面试题及参考答案

cgroup(Control Group)是 Linux 内核提供的一种可以限制、控制与分离一个进程组群的资源(如 CPU、内存、磁盘 I/O 等)的机制。通过 cgroup,可以为不同的进程或进程组分配特定的资源配额,实现资源的隔离和管理。比如,在一个服务器上运行多个容器时,可以使用 cgroup 来限制每个容器对 CPU 和内存的使用,防止某个容器占用过多资源而影响其他容器的运行。cgroup 还可以对进程进行优先级设置,确保关键进程能够优先获得资源。

大模型大数据攻城狮的专栏 1236

POJ 2513 Colored Sticks(字典树+并查集连通性+欧拉回路)

题目地址:POJ 2513 刚开始没想到字典树,用的map函数一直TLE,由于上一次的签到题由于没想到字典树而卡了好长时间的深刻教训,于是过了不久就想起来用字典树了,(为什么是在TLE了5次之后。。T^T)是在然后把map改成了字典树,然后就过了。 这题居然不知不觉的用上了欧拉回路。。其实当时我是这样想的。。因为相互接触的必须要相同,所以除了两端外,其他的都是两两相同的,所以除了两端的颜色外其

scf0920 1202

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

POJ 2513 Colored sticks(字典树 + 欧拉回路 + 并查集)

解题思路: 题目意思很简单,就是判断能否形成欧拉回路,用并查集判断是否连通,然后统计一下每个节点的度数即可。不过因为输入的是字符串,需要对字符串重新编号,用map会导致超时,因此采用字典树。 #include #include #include #include #include #include #include using namespace std; const int M

蘑菇--走在通往梦想的道路上。 542

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

POJ2513 Colored Sticks(字典树+并查集+欧拉回路)

Colored Sticks Time Limit: 5000MS   Memory Limit: 128000K Total Submissions: 33185   Accepted: 8729 Description You are given a bunch of wooden sticks. Each endpoint of

GKHack's Blog 1064

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

poj 2513 Colored Sticks (字典树,并查集,欧拉回路)

N根木棍,两头都有颜色,拼接的时候,必须将颜色一致的接在一起,问能否把全部木棍拼成一整根? 1.颜色映射到数字 map效率低,超时。因此用字典树。 2.判断能否形成通路 条件:所有点的度数都是偶数,或者只有两个点的度数是奇数 (dad是并查集的数组,判断是否全部连通) for(int i=0;i<color;i++) { if(dad[i]==-1) dadcnt++;

JasonWu的博客 239

POJ 2513 Colored Sticks(欧拉回路+字典树+并查集)

题意: 给你很多对单词,单词相当于一个点,一对单词相当于一条边,问这么多对的单词能否组成一条欧拉路,要求每条边都要经过。 解析: 题目数据很大,每个单词最多10个字母,据说用map映射会TLE。 所有要改用字典树进行hash。 判断欧拉路径或者回路需要满足两个条件。 图上所有点联通 度数为奇数个的节点只有0个或者2个。 具体做法: 判断连通性就用并查集,判断是否只

小G的ACM之路 700

POJ 2513 Colored Sticks(字典树 + 并查集 + 欧拉回路)

Colored Sticks Time Limit:5000MS Memory Limit:128000K Total Submissions:23116 Accepted:6095 Description You are given a bunch of wooden...

weixin_30251587的博客 205

POJ 2513 Colored Sticks (欧拉回路 + 字典树 +并查集)

Colored Sticks Time Limit: 5000MS   Memory Limit: 128000K Total Submissions: 27097   Accepted: 7175 Description You are given a bunch of wooden sticks. Each endpoin...

weixin_34138521的博客 118

POJ 2513 Colored Sticks 并查集 + 字典树 + 欧拉回路

把每种颜色看做是图的顶点,然后判定是否满足欧拉回路的条件,用并查集来判断图的各个点是否连通(即是否只用一颗树),用字典树记录颜色编号。 1.字典树: 本题数据比较大,有50W种颜色,如果用STL的map来记录颜色或人工处理的话都会超时(平均O(n/2));所以我们用字典树来记录颜色的编号(平均O(lgn)),大大节约了时间。 2.欧拉回路判定: 本题显然是单向图,用d[]数组来统计每种颜色

Nicolas 1043

POJ 2513 Colored Sticks(字典树,并查集,欧拉回路)

题目大意: 有很多根木棒,木棒两头各有颜色,问能不能将木棒首位相连。使得连接的地方颜色相同。 思路分析: 简单的欧拉回路的判断,用并查集判断联通性。 如果允许的话也可以用map做,但是会超时。 所以用字典树判断单词出现的位置。 坑点是会有木棒数量为0 的情况 #include #include #include #include #pragma com

Jinx Jinx again 1079

poj 2513 Colored Sticks (字典树+并查集+无向图的欧拉回路。)

题目链接:http://poj.org/problem?id=2513 题目大意就是:给你一些棍子,每根棍子两端涂着颜色,颜色相同的两端可以连在一起,问所有棍子可不可以连在一起。 类似于hdu的1116(链接:http://acm.hdu.edu.cn/showproblem.php?pid=1116),差别是1116看的是字母,这看的是单词,这要麻烦些,而且1116是有向图,这是无向

qqspeed 841

POJ 2513 Colored Sticks (欧拉回路 + 并查集 + 字典树)

题目链接:http://poj.org/problem?id=2513 题意:有n段木头,每段木头的两端都有颜色。相同颜色的木头能拼接在一起成为一段。问是否能把所有木头拼接在一起。成为一段。 题解:这道题,和刘汝佳的紫书上的一道题欧拉回路的题目很像,据说这道题map映射会超时,所以映射就用字典树来代替。那么这道题的思路就可以变成,每个木头分成两段,然后每个端点的颜色hash成一个点。连接之后判...

PK__PK的博客 292

poj-2513-Colored Sticks-字典树trie / hash +并查集 欧拉回路

..........一看到题。。试着用hash水一下。。wa 用map水一下TLE。。 好吧。。trie试一下。。。wa .wa .wa..... 好吧。。最后发现是自己傻逼了。。。         窝一开始犯了傻逼错误,以为 直接 计算颜色出现的种数。。。奇数个数的颜色为0或2 就 合法。。然而这只是必要条件.....不是充分条件...........

缺氧 516

poj2513 Colored Sticks —— 字典树 + 并查集 + 欧拉回路

题目链接:http://poj.org/problem?id=2513 题解:通过这题了解了字典树。用字典树存储颜色,并给颜色编上序号。这题为典型的欧拉回路问题:将每种颜色当成一个点。首先通过并查集判断是否为连通图,再检验是否符合欧拉回路的特点。不过题目有一点很奇怪,在并查集中,若图为连通,不是有且仅有一个点的fa[]等于它自己吗,即类似于根节点?为什么会出现有0个的情况,这一...

weixin_30407099的博客 94
上一篇: STL vector用法
下一篇: POJ Black Box 1442(优先队列)
K_y
K_y
博客等级 码龄10年 4粉丝 74原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值