POJ 1300-read comprehension + disgusting input + Euler's loop

Source: Internet
Author: User

I cannot understand the meaning of the question .... in general: It starts from a specified room... can I return to room 0... and close all the doors in the figure .. the door cannot be opened after being closed...

The input is amazing. I read a row in gets and then process it...

Abstract some more... open the door as an edge .. so it is equivalent to finding a path .. to facilitate all sides .. and each side is traversed only once... there are two cases .. one is to start from 0 .. after finishing all the edges, return to 0... this is a typical Euler loop... the other is starting from other points .. reached 0 .. and finish all the edges ..

Determine whether an image can have Euler's loop .. is to see if the degrees of all vertices are even... because all vertices must enter the number of times and the number of times they will go out... it's just a path rather than a loop .. then the start point and the end point must be an odd number of degrees .. the degrees of other points must be an even number...

Program:

#include<iostream>#include<stdio.h>#include<algorithm>#include<string.h>#include<math.h>#include<map>#include<queue>#include<stack>#define ll long long#define oo 1000000000#define pi acos(-1)using namespace std;  int m,n,ans,a[105];char s[505];int main(){      int p,len,i,k;     while (~scanf("%s",s))     {           if (s[0]!='S') break;           scanf("%d%d",&m,&n);           gets(s);           memset(a,0,sizeof(a));           ans=0;           for (p=0;p<n;p++)           {                 gets(s);                 len=strlen(s);                 i=0;                 while (i<len)                 {                       k=0;                       while (s[i]>='0' && s[i]<='9')                       {                              k=k*10+s[i]-'0';                              i++;                         }                       if (k)                       {                              a[p]++;                              a[k]++;                              ans++;                                  k=0;                       }                       i++;                 }           }           gets(s);           k=0;           for (i=0;i<n;i++)              if (a[i]%2) k++;            if (!m)           {               if (!k)                   printf("YES %d\n",ans);                   else                   printf("NO\n");            }else           {               if (k==2 && a[m]%2 && a[0]%2)                   printf("YES %d\n",ans);                   else                   printf("NO\n");                           }     }     return 0;}

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.