hdu-5813 Elegant Construction(贪心)
题目链接:
Elegant Construction
Time Limit: 4000/2000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
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!
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.
#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(贪心)的更多相关文章
- HDU 5813 Elegant Construction(优雅建造)
HDU 5813 Elegant Construction(优雅建造) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65 ...
- HDU 5813 Elegant Construction (贪心)
Elegant Construction 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5813 Description Being an ACMer ...
- HDU 5813 Elegant Construction 构造
Elegant Construction 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5813 Description Being an ACMer ...
- HDU 5813 Elegant Construction
构造.从a[i]最小的开始放置,例如放置了a[p],那么还未放置的,还需要建边的那个点 需求量-1,然后把边连起来. #pragma comment(linker, "/STACK:1024 ...
- HDU 5813 Elegant Construction ——(拓扑排序,构造)
可以直接见这个博客:http://blog.csdn.net/black_miracle/article/details/52164974. 对其中的几点作一些解释: 1.这个方法我们对队列中取出的元 ...
- HDU5813 Elegant Construction
Elegant Construction Time Li ...
- HDU 4442 Physical Examination(贪心)
HDU 4442 Physical Examination(贪心) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=4442 Descripti ...
- UVA 10720 Graph Construction 贪心+优先队列
题目链接: 题目 Graph Construction Time limit: 3.000 seconds 问题描述 Graph is a collection of edges E and vert ...
- HDU 5835 Danganronpa (贪心)
Danganronpa 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5835 Description Chisa Yukizome works as ...
随机推荐
- Android日期对话框NumberPicker的使用方法教程
NumberPicker是Android3.0之后引入的一个控件.NumberPicker 是用于选择一组提前定义好数字的控件.比方时间hour的选择仅仅有0-23有效,则能够通过setMinValu ...
- BC 1.2 模式(Battery Charging Specification 1.2)
转自:http://blog.csdn.net/liglei 转自:http://blog.csdn.net/liglei/article/details/22852755 USB BC1.2有以下三 ...
- (最短路径算法整理)dijkstra、floyd、bellman-ford、spfa算法模板的整理与介绍
这一篇博客以一些OJ上的题目为载体.整理一下最短路径算法.会陆续的更新... 一.多源最短路算法--floyd算法 floyd算法主要用于求随意两点间的最短路径.也成最短最短路径问题. 核心代码: / ...
- Highcharts使用表格数据绘制图表
Highcharts使用表格数据绘制图表 在Highcharts中,同意用户使用网页中现有的表格数据作为数据来源,然后依据该数据来源绘制图表.对于一个典型的HTML表格.当中,第一列的数据会作为x轴刻 ...
- 一、Silverlight中使用MVVM(一)——基础
如果你不知道MVVM模式,我建议你先了解一下MVVM模式,至少要知道实现该模式的意图是什么. 那么我主要通过我认为是已经算是比较简单的例子进行讲解这个模式,当然后面我们会在这个例子的基础上一步一步的进 ...
- XMPP协议概述
XMPP(Extensible Messaging and Presence Protocol,前称Jabber)是一种以 XML 为基础的开放式实时通信协议,关于它的协议细节,网上已经有太多分析文章 ...
- tao.opengl+C#绘制三维模型
一.tao.Opengl技术简介 Opengl是一种C风格的图形库,即opengl中没有类和对象,只有大量的函数.Opengl在内部就是一个状态机,利用不同的函数来修改opengl状态机的状态,以达到 ...
- ASP.NET MVC 4 技术讲解
ASP.NET MVC 相关的社群与讨论区 Routing 与 ASP.NET MVC 生命周期 Model相关技术 Controller相关技术 View数据呈现相关技术 Area区域相关技术 AS ...
- JavaMelody tomcat应用监控
1 下载相关jar包,maven地址 测试发现 1.57.0版本tomcat6工程登陆报错,改用版本 1.50.0是正常的 <dependency> <groupId>net. ...
- MySQL中使用INNER JOIN来实现Intersect并集操作
MySQL中使用INNER JOIN来实现Intersect并集操作 一.业务背景 我们有张表设计例如以下: CREATE TABLE `user_defined_value` ( `RESOURCE ...