URAL 1035 Cross-stitch

Source: Internet
Author: User

A graph of the simulation questions,,,,,//So you're a jerk,,,,, Euler path AH!!!!!!!!

The slash represents the seam line, each lattice vertex can want to do is to have a small hole can wear the past,, and then the idea of the normal stitches,,, asked to sew out the pattern of the minimum number of steps,,,,, sew over, sew the past ~

The beginning is to fully simulate (that is, a situation to write a function), but once through a face, there are 4 situations ...

The result is 200+ line, but still wrong ...

Give a few sets of examples

5 4
.. \/
\/..
/x..
.. x/
.. X.
.. X.
\/\/
\/..
\/..
\/..
Ans:13
3 3
.. \
/\x
...
.. \
///
...
Ans:2

I think a good solution is to ask for the degrees and degrees of each point and then see how many odd ... Have not been verified.

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <bits/stdc++.h>
using namespace Std;

int p[40500],a[40500][2],sum[40500],n,m;

int find (int x)
{
if (p[x]!=x) P[x]=find (p[x]);
return p[x];
}
int judge (int x,int y)
{
Return (Find (x) ==find (y))? 1:0;
}
void make (int side)
{
int ul,ur,dl,dr;
char c;
for (int i=0;i<n;i++)
for (int j=0;j<m;j++)
{
cin>>c;
ul=i* (m+1) +j;ur=ul+1;
Dl= (i+1) * (m+1) +j;dr=dl+1;
if ((c== ' X ') | | (c== ' \ \ '))
{
a[ul][side]++;a[dr][side]++;
if (!judge (UL,DR)) P[P[UL]]=P[DR];
}
if ((c== ' X ') | | (c== '/'))
{
a[ur][side]++;a[dl][side]++;
if (!judge (UR,DL)) P[P[UR]]=P[DL];
}
}
}

int main ()
{
scanf ("%d%d", &n,&m);
int i,j,ans=0;
For (i=0;i< (m+1) * (n+1); i++) p[i]=i;
Make (0);
Make (1);
For (i=0;i< (m+1) * (n+1); i++)
{
if (a[i][0]| | A[I][1]) sum[find (i)]+=abs (a[i][0]-a[i][1]);
}
For (i=0;i< (m+1) * (n+1); i++)
{
if (a[i][0]| | A[I][1]) && (p[i]==i)) ans+=sum[i]?sum[i]/2:1;
}
printf ("%d\n", ans);
return 0;
}


In fact, it's better to use DFS,,, to merge the situation together,,,,,,

Hey




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

URAL 1035 Cross-stitch

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.