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

For business purpose, the connectivity between towns has some requirements. You are given N non-negative integers a1 .. aN. For 1 <= i <= N, passenger start from town i, should be able to reach exactly ai towns (directly or indirectly, not include i itself). To prevent confusion on the trip, every road should be different, and cycles (one can travel through several roads and back to the starting point) should not exist.

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

InputThe first line is an integer T (T <= 10), indicating the number of test case. Each test case begins with an integer N (1 <= N <= 1000), indicating the number of towns. Then N numbers in a line, the ith number ai (0 <= ai < N) has been described above.OutputFor each test case, output "Case #X: Y" in a line (without quotes), where X is 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", output an integer M in a line, indicating the number of roads. Then M lines follow, each line contains two integers u and v (1 <= u, v <= N), separated with one single space, indicating a road direct from town u to town v. If there are multiple possible solutions, print any of them. 
Sample Input

3
3
2 1 0
2
1 1
4
3 1 1 0

Sample Output

Case #1: Yes
2
1 2
2 3
Case #2: No
Case #3: Yes
4
1 2
1 3
2 4
3 4 启发来自于队内大佬余神和楼主
首先判读能否构成这样的有向无环图,对拿到的出度进行排序,然后看比一个点出度小的点数有没有小于等于它本身的出度,如果有大于的则输出no,全部小于等于则输出yes
判断yes后,有一个最傻瓜的思路,就是全先连0,然后连1,然后连下去。因为小的数连完以后再连大的数之后就不用考虑大数所连数,直接+1即可。
 #include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std; int b[]; struct node
{
int u,v;
node(int x,int y){u=x;v=y;}
}; struct node2
{
int num,id;
}a[]; bool cmp(node2 m,node2 n)
{
return m.num<n.num;
}
int main()
{
int T;
scanf("%d",&T);
for(int t=;t<=T;t++)
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i].num);
a[i].id=i;
}
printf("Case #%d: ",t);
sort(a+,a+n+,cmp);
memset(b,,sizeof(b));
int s=,tmp=;
for(int i=;i<=n;i++)
{ if(a[i].num==a[i-].num)
{
b[i]=s;
tmp++;
}
else
{
s+=tmp;
b[i]=s;
tmp=;
}
}
bool flag=true;
for(int i=;i<=n;i++)
if(a[i].num>b[i])
{
flag=false;
break;
}
if(!flag)
printf("No\n");
else
{
printf("Yes\n");
queue<node>Q;
int num=;
for(int i=;i<=n;i++)
{
for(int j=;j<=a[i].num;j++)
{
Q.push(node(a[i].id,a[j].id));
num++;
}
}
printf("%d\n",num);
while(!Q.empty())
{
printf("%d %d\n",Q.front().u,Q.front().v);
Q.pop();
}
}
}
return ;
}
 

2016 多校联赛7 Elegant Construction的更多相关文章

  1. hdu5737(2016多校联赛第2场D)

    题意:给2组数据a和b数组,每次有2种操作:(+,l,r,x)把a数组第l个到第r个元素全置为x,(?,l,r)查询[l,r]之间哪些位置满足a[i]>=b[i](i>=l &&a ...

  2. 2016 多校联赛7 Joint Stacks (优先队列)

    A stack is a data structure in which all insertions and deletions of entries are made at one end, ca ...

  3. 2016 多校联赛7 Balls and Boxes(概率期望)

    Mr. Chopsticks is interested in random phenomena, and he conducts an experiment to study randomness. ...

  4. HDU 5813 Elegant Construction (贪心)

    Elegant Construction 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5813 Description Being an ACMer ...

  5. HDU5813 Elegant Construction

    Elegant Construction                                                                         Time Li ...

  6. HDU 5813 Elegant Construction(优雅建造)

    HDU 5813 Elegant Construction(优雅建造) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65 ...

  7. HDU 5813 Elegant Construction 构造

    Elegant Construction 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5813 Description Being an ACMer ...

  8. 2015 HDU 多校联赛 5363 Key Set

    2015 HDU 多校联赛 5363 Key Set 题目: http://acm.hdu.edu.cn/showproblem.php? pid=5363 依据前面给出的样例,得出求解公式 fn = ...

  9. 2015 HDU 多校联赛 5317 RGCDQ 筛法求解

    2015 HDU 多校联赛 5317 RGCDQ 筛法求解 题目  http://acm.hdu.edu.cn/showproblem.php? pid=5317 本题的数据量非常大,測试样例多.数据 ...

随机推荐

  1. 剑指offer-整数中1出现的次数

    题目描述 求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数?为此他特别数了一下1~13中包含1的数字有1.10.11.12.13因此共出现6次,但是对于后面问题他就没辙了. ...

  2. SEND EMAIL SO_DOCUMENT_SEND_API1

    FUNCTION zcrm_send_email_and_attach . *"------------------------------------------------------- ...

  3. PostgreSQL导出一张表到MySQL

    1. 查看PostgreSQL表结构,数据量,是否有特殊字段值 region_il=# select count(*) from result_basic; count --------- ( row ...

  4. Hibernate -- lazy加载

    Hibernate -- lazy加载 hibernate类级别懒加载: lazy:true(默认) //类级别懒加载 //load方法 //class lazy属性 //默认值:true load获 ...

  5. 【转】Vue-详解设置路由导航的两种方法: <router-link :to="..."> 和router.push(...)

    一.<router-link :to="..."> to里的值可以是一个字符串路径,或者一个描述地址的对象.例如: // 字符串 <router-link to= ...

  6. RESTful API单元测试(十九)

    下面针对该Controller编写测试用例验证正确性,具体如下.当然也可以通过浏览器插件等进行请求提交验证. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...

  7. TCP可靠传输:校验和,重传控制,序号标识,滑动窗口、确认应答

    Tcp通过校验和,重传控制,序号标识,滑动窗口.确认应答实现可靠传输 应答码:ACK TCP的滑动窗口机制       TCP这个协议是网络中使用的比较广泛,他是一个面向连接的可靠的传输协议.既然是一 ...

  8. HTML中元素的position属性详解

    HTML中元素的position属性详解 转载自:https://blog.csdn.net/wangzunkuan/article/details/81540935   HTML中DOM元素有5种定 ...

  9. OPENWRT安装配置指南之 17.01.4 LEDE

    简介 这个东西,需要看简介的就不要看下去了. 下面已刚刷进去,路由IP地址为192.168.1.1为例开始配置. 浏览器访问192.168.1.1,无密码. 一:配置上网 不管你是什么方式上网,请根据 ...

  10. 读书笔记 C# Type类型与泛型有关的某些属性浅析

    IsGenericType 如果类型为泛型,则返回 true. GetGenericArguments 返回 Type 对象数组,这些对象表示为构造类型提供的类型变量,或泛型类型定义的类型参数.如果是 ...