Elegant Construction---hdu5813 (tectonic chart)

Source: Internet
Author: User

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

Test instructions is: There are n points, each point can reach num points, let us construct any one to meet the conditions, that is: so I can reach a[i] points;

The vertices are sorted from small to large by the number of points that can be reached, and each point can only be connected to the front point when ordered. So we have to make the number of points above or equal to the number of points it is to be connected;

Thus, if there is a point at the i-1 (preceded by a point), the i-1>= requires the arrival of the points (i> required to reach the points);

The diagram is constructed according to the above method. Complexity O (n^2).

#include <cstring>#include<cstdio>#include<iostream>#include<algorithm>#include<cmath>#include<stack>#include<vector>#include<queue>using namespacestd;#defineN 1005#defineMet (A, b) memset (A, B, sizeof (a))typedefLong LongLL;structnode{intId, num; FriendBOOL operator<(node p, node Q) {returnP.num <Q.num; }}a[n];intU[n*n], v[n*N];intMain () {intT, T =1, N; scanf ("%d", &T);  while(t--) {scanf ("%d", &N);  for(intI=1; i<=n; i++) {scanf ("%d", &a[i].num); A[i]. Id=i; } sort (A+1, a+n+1); intK =0, flag =0;  for(intJ=m; i>=1; i--)        {            if(A[i].num >= i)///the number of previous points must be greater than the number of points it is to reach;{flag=1;  Break; }             for(intj=1; j<=a[i].num; J + +)///we can use a[i] because we just output a set of qualified solutions. ID to connect any of the Num bar a[j]. Id (J< i);            {U[K] =A[i].                Id; V[k++] =A[j].            Id; }        }        if(flag) printf ("Case #%d:no\n", t++); Else{printf ("Case #%d:yes\n", t++); printf ("%d\n", K);  for(intI=0; i<k; i++) printf ("%d%d\n", U[i], v[i]); }    }    return 0;}/*332 1 021 143 1 1 0*/
View Code

Elegant Construction---hdu5813 (tectonic chart)

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.