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. UI基础七:给普通其他界面的PRODUCT 添加标准的搜索帮助

    在使用的组件中添加组件对象 Outbound Plug中添加外向连接:OP_PRODUCT METHOD op_product. DATA: lv_title TYPE string, lr_cont ...

  2. 2017-6-5/MySQL分库分表

    分库分表,顾名思义,就是把原本存储于一个库一张表的数据分块存储到多个库多张表上.对于大型互联网应用来说,当一张表的数据量达到百万.千万时,数据库每执行一次查询所花的时间会变多,并且数据库面临着极高的并 ...

  3. 码云插件Gitee:Couldn't get the list of Gitee repositories

    20:02 Couldn't get the list of Gitee repositories Can't get available repositories Not Found

  4. [CodeForces - 614B] B - Gena's Code

    B - Gena's Code It's the year 4527 and the tanks game that we all know and love still exists. There ...

  5. Web Services的学习一

    1.Web Services可以将应用程序转换成为网络应用程序,也就是说可以通过Web Services,应用程序可以向全世界发布信息,或者提供功能. 而且通过Web Services发布的,可以被其 ...

  6. loj 10004 智力大冲浪

    智力大冲浪 题目描述: 小伟报名参加中央电视台的智力大冲浪节目.本次挑战赛吸引了众多参赛者,主持人为了表彰大家的勇气,先奖励每个参赛者m元.先不要太高兴!因为这些钱还不一定都是你的.接下来主持人宣布了 ...

  7. MySQL升级教程(CentOS)

    1.支持的升级方式 原地升级(In-Place Upgrade):直接替换二进制文件(即直接yum update/rpm -Uvh升级rpm包)数据库目录等都不变. 逻辑升级(Logical Upgr ...

  8. [转]关于ReentrantLock中线程读某个变量是否需要加锁

    我在使用ReentrantLock类对变量进行多线程累加时,调用了lock()和unlock()方法,但读取该变量时我未加锁,结果是能正确执行,代码如下: public class Main { pr ...

  9. 使用web3+solc编译发布以太坊智能合约

    一.环境安装: 1.安装web3工程:npm install web3 2.安装solc工程:npm install solc二.在node环境中使用 先引用所需环境: var fs = requir ...

  10. css制作tips提示框,气泡框,制作三角形

    有时候我们的页面会需要这样的一些提示框或者叫气泡框,运用css,我们可以实现这样的效果. 为了实现上面的效果,我们首先要理解如何制作三角形. 当我们给一个DIV不同颜色的边框的时候,我们可以得到下面的 ...