题意:中文题。

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

代码如下:

  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include <cstdio>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <cmath>
  6. #include <iostream>
  7. #include <cstring>
  8. #include <set>
  9. #include <queue>
  10. #include <algorithm>
  11. #include <vector>
  12. #include <map>
  13. #include <cctype>
  14. #include <cmath>
  15. #include <stack>
  16. #define lson l,m,rt<<1
  17. #define rson m+1,r,rt<<1|1
  18. //#include <tr1/unordered_map>
  19. #define freopenr freopen("in.txt", "r", stdin)
  20. #define freopenw freopen("out.txt", "w", stdout)
  21. using namespace std;
  22. //using namespace std :: tr1;
  23.  
  24. typedef long long LL;
  25. typedef pair<int, int> P;
  26. const int INF = 0x3f3f3f3f;
  27. const double inf = 0x3f3f3f3f3f3f;
  28. const LL LNF = 0x3f3f3f3f3f3f;
  29. const double PI = acos(-1.0);
  30. const double eps = 1e-8;
  31. const int maxn = 1e5 + 5;
  32. const LL mod = 10000000000007;
  33. const int N = 1e6 + 5;
  34. const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
  35. const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
  36. const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
  37. inline LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }
  38. int n, m;
  39. const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  40. const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  41. inline int Min(int a, int b){ return a < b ? a : b; }
  42. inline int Max(int a, int b){ return a > b ? a : b; }
  43. inline LL Min(LL a, LL b){ return a < b ? a : b; }
  44. inline LL Max(LL a, LL b){ return a > b ? a : b; }
  45. inline bool is_in(int r, int c){
  46. return r >= 0 && r < n && c >= 0 && c < m;
  47. }
  48. struct Node{
  49. int id, num;
  50. bool operator < (const Node &p) const{
  51. return num > p.num;
  52. }
  53. };
  54. Node a[15];
  55. int ans[15][15];
  56.  
  57. int main(){
  58. int T; cin >> T;
  59. while(T--){
  60. scanf("%d", &n);
  61. for(int i = 0; i < n; ++i){
  62. scanf("%d", &a[i].num);
  63. a[i].id = i;
  64. }
  65.  
  66. bool ok = true;
  67. memset(ans, 0, sizeof ans);
  68. for(int i = 0; i < n; ++i){
  69. sort(a+i, a+n);
  70. for(int j = i+1; j < n; ++j){
  71. if(a[i].num && a[j].num){
  72. ans[a[i].id][a[j].id] = ans[a[j].id][a[i].id] = 1;
  73. --a[i].num;
  74. --a[j].num;
  75. }
  76. else break;
  77. }
  78. if(a[i].num){ ok = false; break; }
  79. }
  80.  
  81. if(!ok) puts("NO");
  82. else {
  83. puts("YES");
  84. for(int i = 0; i < n; ++i){
  85. for(int j = 0; j < n; ++j)
  86. if(j) printf(" %d", ans[i][j]);
  87. else printf("%d", ans[i][j]);
  88. printf("\n");
  89. }
  90. }
  91. if(T) puts("");
  92. }
  93. return 0;
  94. }

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. LeetCode(70) Climbing Stairs

    题目 You are climbing a stair case. It takes n steps to reach to the top. Each time you can either cli ...

  2. 对Spring框架的理解(转)

    ①  spring框架是一个开源而轻量级的框架,是一个IOC和AOP容器 ② spring的核心就是控制反转(IOC)和面向切面编程(AOP) ③  控制反转(IOC):是面向对象编程中的一种设计原则 ...

  3. webstrom破解-webstrom2018.2.4破解方法(xjl456852原创)

    方法一: 获取注册码: http://idea.lanyus.com/ 方法二: 使用破解补丁 放在安装目录的bin目录下,并且编辑bin目录下的文件 如果使用的32位的webstrom就编辑webs ...

  4. 关于 <customErrors> 标记的“mode”属性设置为“Off”的问题的解决方案

    用 权限问题 <customErrors> 标记的“mode”属性设置为“Off”. 权限问题标记的“mode”属性设置为“Off”.说明: 服务器上出现应用程序错误.此应用程序的当前自定 ...

  5. typeof instanceof操作符的相关知识

    数据类型 ECMAScript中有5中基本数据类型:Undefined Null Boolean Number String. Typeof运算符 对一个值使用typeof操作符可能返回下列某个字符串 ...

  6. BNUOJ 26283 The Ghost Blows Light

    The Ghost Blows Light Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. O ...

  7. [luoguP1944] 最长括号匹配_NOI导刊2009提高(1)

    传送门 非常傻的DP. f[i]表示末尾是i的最长的字串 #include <cstdio> #include <cstring> #define N 1000001 int ...

  8. android中SQLite实现

    SQLite操作类: package com.example.administrator.myapplication; import android.content.Context; import a ...

  9. 博弈论入门题 kiki's game

    Problem Description Recently kiki has nothing to do. While she is bored, an idea appears in his mind ...

  10. Layui颜色

    Layui颜色 视觉疲劳的形成往往是由于颜色过于丰富或过于单一形成的麻木感,而 layui 提供的颜色,清新而不乏深沉,互相柔和,不过分刺激大脑皮层的神经反应,形成越久越耐看的微妙影像.合理搭配,可与 ...