hdu-5813 Elegant Construction (greedy)

Source: Internet
Author: User

Topic Links:

Elegant construction

Time limit:4000/2000 MS (java/others)

Memory limit:65536/65536 K (java/others)

Problem descriptionbeing an acmer requires knowledge in many fields, because problems in this contest could use physics, bio Logy, and even musicology as background. And now on this problem, you is being a city architect!
A City with N towns (numbered 1 through N) is under construction. You, the architect, is being responsible for designing how these towns is connected by one-way roads. Each road connects the towns, and passengers can travel through in one direction.

For business purpose, the connectivity between towns have some requirements. You are given N non-negative integers A1. An. For 1 <= i <= N, passenger start from the town I, should is able to reach exactly AI towns (directly or indirectly, not Include I itself). To prevent confusion on the trip, every road should is different, and cycles (one can travel through several roads and BAC K to the starting point) should not exist.

Your task is constructing such a city. Now it ' s your showtime!

Inputthe first line was an integer t (t <=), indicating the number of the test case. Each test case is begins with an integer n (1 <= n <=), indicating the number of towns. Then N numbers on a line, the ith number ai (0 <= ai < N) have been described above.

Outputfor each test case, output ' case #X: Y ' in a line (without quotes), where X was the case number starting from 1, and Y is "Yes" if you can construct successfully or "No" if it's impossible to reach the requirements.

If Y is "Yes" and output an integer M with a line, indicating the number of roads. Then M lines follow, each line contains the integers u and V (1 <= u, v <= N), separated with one single space, Indi Cating a road direct from the town U-Town v. If There is multiple possible solutions, print any of them.

Sample Input332 1 021 143 1 1 0

Sample outputcase #1: Yes21 3Case #2: nocase #3: Yes41 21 32 43 4 Test instructions: Ask whether there is such a direction-free graph, so that the node labeled I can reach the a[i] nodes; Idea: Sort by size, the number of the first bit should be less than I, even when the picture of the back of the forward connected to the good, even a[i] a good, AC code:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < cmath> #include <bits/stdc++.h> #include <stack> #include <map> using namespace std; #define for (i,j,n) for (int i=j;i<=n;i++) #define MST (SS,B) memset (ss,b,sizeof (ss)); typedef long Long LL;    Template<class t> void Read (t&num) {char CH; bool F=false; For (Ch=getchar (); ch< ' 0 ' | | Ch> ' 9 ';    f= ch== '-', Ch=getchar ()); for (num=0;    ch>= ' 0 ' &&ch<= ' 9 '; num=num*10+ch-' 0 ', Ch=getchar ()); F && (num=-num);}    int stk[70], tp;template<class t> inline void print (T p) {if (!p) {puts ("0"); return;}    while (p) stk[++ TP] = p%10, p/=10;    while (TP) Putchar (stk[tp--] + ' 0 '); Putchar (' \ n ');} Const LL Mod=1e9+7;const double Pi=acos ( -1.0); const int INF=1E18;CONST int N=1e5+10;const int Maxn=5e3+4;const double eps= 1e-12;struct node{int a,id;}    Po[n];int CMP (node X,node y) {if (X.A==Y.A) return x.id<y.id; Return X.a<y. A;}    int main () {int t,case=0,n;    Read (t);        while (t--) {printf ("Case #%d:", ++case);        Read (n);        int sum=0;            for (i,1,n) {read (PO[I].A);            SUM+=PO[I].A;        Po[i].id=i;        } int flag=0;        Sort (po+1,po+n+1,cmp);                for (I,1,n) {if (po[i].a>=i) {flag=1;            Break    }} if (flag) printf ("no\n");        else {printf ("yes\n");        printf ("%d\n", sum);        int num=0; for (I,1,n) {for (int j=1;j<=po[i].a;j++) {printf ("%d%d\n", Po[i].id,po[j].            ID); }}}} return 0;}

  

hdu-5813 Elegant Construction (greedy)

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.