题意:中文题。

析:贪心策略,先让邻居多的选,选的时候也尽量选邻居多的。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
//#include <tr1/unordered_map>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
//using namespace std :: tr1; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 5;
const LL mod = 10000000000007;
const int N = 1e6 + 5;
const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
inline LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
struct Node{
int id, num;
bool operator < (const Node &p) const{
return num > p.num;
}
};
Node a[15];
int ans[15][15]; int main(){
int T; cin >> T;
while(T--){
scanf("%d", &n);
for(int i = 0; i < n; ++i){
scanf("%d", &a[i].num);
a[i].id = i;
} bool ok = true;
memset(ans, 0, sizeof ans);
for(int i = 0; i < n; ++i){
sort(a+i, a+n);
for(int j = i+1; j < n; ++j){
if(a[i].num && a[j].num){
ans[a[i].id][a[j].id] = ans[a[j].id][a[i].id] = 1;
--a[i].num;
--a[j].num;
}
else break;
}
if(a[i].num){ ok = false; break; }
} if(!ok) puts("NO");
else {
puts("YES");
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j)
if(j) printf(" %d", ans[i][j]);
else printf("%d", ans[i][j]);
printf("\n");
}
}
if(T) puts("");
}
return 0;
}

POJ 1659 Frogs' Neighborhood (贪心)的更多相关文章

  1. poj 1659 Frogs' Neighborhood (贪心 + 判断度数序列是否可图)

    Frogs' Neighborhood Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 6076   Accepted: 26 ...

  2. poj 1659 Frogs' Neighborhood (DFS)

    http://poj.org/problem?id=1659 Frogs' Neighborhood Time Limit: 5000MS   Memory Limit: 10000K Total S ...

  3. POJ 1659 Frogs' Neighborhood(可图性判定—Havel-Hakimi定理)【超详解】

    Frogs' Neighborhood Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 9897   Accepted: 41 ...

  4. POJ 1659 Frogs' Neighborhood(Havel-Hakimi定理)

    题目链接: 传送门 Frogs' Neighborhood Time Limit: 5000MS     Memory Limit: 10000K Description 未名湖附近共有N个大小湖泊L ...

  5. POJ 1659 Frogs' Neighborhood (Havel--Hakimi定理)

    Frogs' Neighborhood Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 10545   Accepted: 4 ...

  6. poj 1659 Frogs' Neighborhood( 青蛙的邻居)

    Frogs' Neighborhood Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 9639   Accepted: 40 ...

  7. Poj 1659.Frogs' Neighborhood 题解

    Description 未名湖附近共有N个大小湖泊L1, L2, ..., Ln(其中包括未名湖),每个湖泊Li里住着一只青蛙Fi(1 ≤ i ≤ N).如果湖泊Li和Lj之间有水路相连,则青蛙Fi和 ...

  8. poj 1659 Frogs' Neighborhood(出入度、可图定理)

    题意:我们常根据无向边来计算每个节点的度,现在反过来了,已知每个节点的度,问是否可图,若可图,输出一种情况. 分析:这是一道定理题,只要知道可图定理,就是so easy了  可图定理:对每个节点的度从 ...

  9. poj 1659 Frogs' Neighborhood Havel-Hakimi定理 可简单图定理

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4098136.html 给定一个非负整数序列$D=\{d_1,d_2,...d_n\}$,若存 ...

随机推荐

  1. 牛客网NOIP赛前集训营 第6场 T1 最长路

    [题解] 先建反向图,然后跑拓扑排序求出最长路. 将所有的点按照最长路从小到大分层,把上一层连向这一层的边按照边权为第一关键字.起点的排名为第二关键字排序. 按照这个顺序更新这一层的答案,按照这一层每 ...

  2. BNUOJ 1589 Closest Common Ancestors

    Closest Common Ancestors Time Limit: 2000ms Memory Limit: 10000KB This problem will be judged on PKU ...

  3. 全文搜索(A-3)-用户建模

    用户模型可以分为静态模型.动态模型.混合推荐用户模型. 静态模型往往通过显式方式收集用户偏好信息: 动态模型通过隐式方式收集用户偏好信息: 基于内容的用户系统的推荐模型: 关键字匹配,空间向量模型 协 ...

  4. 【Linux】date命令用法详解(日期格式)

    inux下date命令用法 date [OPTION]… [+FORMAT] date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] date命令参数 ...

  5. 使用mysql-proxy 快速实现mysql 集群 读写分离

    目前较为常见的mysql读写分离分为两种: 1. 基于程序代码内部实现:在代码中对select操作分发到从库:其它操作由主库执行:这类方法也是目前生产环境应用最广泛,知名的如DISCUZ X2.优点是 ...

  6. Thinkphp5.0 的使用模型Model的获取器与修改器

    Thinkphp5.0 的使用模型Model的获取器.修改器.软删除 一.获取器 在model中使用 get+字段名+Attr,可以修改字段的返回值. 数据库中性别保存为,0未知.1男.2女,查询时返 ...

  7. [bzoj3489]A simple rmq problem_KD-Tree

    A simple rmq problem 题目大意:给定一个长度为$n$的序列,给出$m$个询问:在$[l,r]$之间找到一个在这个区间里只出现过一次的最大的数. 注释:$1\le n\le 10^5 ...

  8. how to read openstack code : routes

    When coding a web system, you have to think about an important problem, how to map urls to logic. Op ...

  9. 介绍css 的3D 变换(3D transform)

    https://desandro.github.io/3dtransforms/docs/card-flip.html ---------------------------------------- ...

  10. 【大数据处理架构】1.spark streaming

    1. spark 是什么? >Apache Spark 是一个类似hadoop的开源高速集群运算环境  与后者不同的是,spark更快(官方的说法是快近100倍).提供高层JAVA,Scala, ...