[2015HDU Multi-School League title]hdu5302 Connect the Graph

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5302

Test instructions: give you an image with no direction, its edge is either black or white, and each point on the graph is connected to a maximum of two black edges with two white edges. Now, demon divides the diagram into two parts, one part contains all the black edges, the other part includes all the white edges, gives you the number of points in the white edge of the figure of 0 W0, the degree of 1 points W1, the degree of 2 points W2, and the black edge of the figure of 0 points B1, the degree of 1 points B1, 2 points B2, I want you to output any one of the eligible originals, if not, output-1

(Note 1: Whether it is a black edge or a white-edged graph, the given degree is 0, 1, 23 points of the quantity are >=1;

Note 2:W0+W1+W2==B0+B1+B2, the output graph of the number of points is w0+w1+w2;

Note 3: There is no heavy edge, no self-loop;

Solution: Construction Problem

Consider that each edge corresponds to two degrees, then the W1 or B1 is an odd number must be no solution

Excluding the above situation, there are w1>=2 && b1>=2, the two-degree point in a row, link up in sequence, and then the first and last points are connected to one point, the remaining point 22 connected to each other

So that we can solve the black or white, considering the above-mentioned construction method, each point and the adjacent points are connected, after we construct a diagram, the other one only need to slightly disturb the order of the next point

For example:

1 2 3 4 5-1 4 2 5 3

Another n==4 need to be a special sentence ...

1 /*2 * problem:hdu5302 Connect the Graph3 * AUTHOR:SHJWUDP4 * Created TIME:2015/8/10 Monday 19:24:325 * File name:1006.cpp6 * state:accepted7 * Memo: Construction8  */9#include <iostream>Ten#include <cstdio> One#include <vector> A#include <cstring> -#include <algorithm> -  the using namespacestd; -  - intMain () { - #ifndef Online_judge +Freopen ("inch","R", stdin); -     //freopen ("Out", "w", stdout); + #endif A     intT; atscanf"%d", &T); -      while(t--) { -vector<int> W (3), B (3); -          for(intI=0; i<3; i++) scanf ("%d", &w[i]); -          for(intI=0; i<3; i++) scanf ("%d", &b[i]); -         if((w[1] &1) || (b[1] &1)) { inPuts"-1");Continue; -         } to         intn=w[0]+w[1]+w[2]; +         if(n<=4) { -Puts"4\n1 2 0\n1 3 0\n2 3 1\n3 4 1");Continue;  the         } *         intm1=w[2]+w[1]/2; $         intm2=b[2]+b[1]/2;Panax Notoginsengprintf"%d\n", m1+m2); -         intnw=1; thew[2]++; +          while(w[2]--) { Aprintf"%d%d 0\n", NW, nw+1); nw++; the         } +w[1]-=2; nw++; -          while(w[1]) { $printf"%d%d 0\n", NW, nw+1); nw+=2; $w[1]-=2; -         } -vector<int> Table (n+1); the         intpos=1; -          for(intI=1; i<=n; i+=2) table[pos++]=i;Wuyi          for(intI=2; i<=n; i+=2) table[pos++]=i; the         intnb=1; -b[2]++; Wu          while(b[2]--) { -printf"%d%d 1\n", TABLE[NB], table[nb+1]); nb++; About         } $b[1]-=2; nb++; -          while(b[1]) { -printf"%d%d 1\n", TABLE[NB], table[nb+1]); nb+=2; -b[1]-=2; A         } +     } the     return 0; -}
hdu5302

[2015HDU Multi-School League title]hdu5302 Connect the Graph

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.