zoukankan      html  css  js  c++  java
  • POJ 1659 Frogs' Neighborhood

    Frogs' Neighborhood
    Time Limit: 5000MS   Memory Limit: 10000K
    Total Submissions: 4928   Accepted: 2169   Special Judge

    Description

    未名湖附近共有N个大小湖泊L1, L2, ..., Ln(其中包括未名湖),每个湖泊Li里住着一只青蛙Fi(1 ≤ iN)。如果湖泊LiLj之间有水路相连,则青蛙FiFj互称为邻居。现在已知每只青蛙的邻居数目x1, x2, ..., xn,请你给出每两个湖泊之间的相连关系。

    Input

    第一行是测试数据的组数T(0 ≤ T ≤ 20)。每组数据包括两行,第一行是整数N(2 < N < 10),第二行是N个整数,x1, x2,..., xn(0 ≤ xiN)。

    Output

    对输入的每组测试数据,如果不存在可能的相连关系,输出"NO"。否则输出"YES",并用N×N的矩阵表示湖泊间的相邻关系,即如果湖泊i与湖泊j之间有水路相连,则第i行的第j个数字为1,否则为0。每两个数字之间输出一个空格。如果存在多种可能,只需给出一种符合条件的情形。相邻两组测试数据之间输出一个空行。

    Sample Input

    3
    7
    4 3 1 5 4 2 1 
    6
    4 3 1 4 2 0 
    6
    2 3 1 1 2 1 
    

    Sample Output

    YES
    0 1 0 1 1 0 1 
    1 0 0 1 1 0 0 
    0 0 0 1 0 0 0 
    1 1 1 0 1 1 0 
    1 1 0 1 0 1 0 
    0 0 0 1 1 0 0 
    1 0 0 0 0 0 0 
    
    NO
    
    YES
    0 1 0 0 1 0 
    1 0 0 1 1 0 
    0 0 0 0 0 1 
    0 1 0 0 0 0 
    1 1 0 0 0 0 
    0 0 1 0 0 0 
    

    Source


    //可图化问题
    给你图中每个点个数、求符合条件的一个图
    算法
    1.将度数排序 将度数d最大删除
    2.在接下来d个数分别减1
    转 1 直到都为 0
    如果中间出现某个度数为 负、则代表不可图化

    #include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; #define N 12 struct ID { int id,x; bool operator <(const ID& b)const { return x>b.x; } }st[N]; int map[N][N]; int main() { int T; bool f=0; scanf("%d",&T); while(T--) { if(!f) f=true; else printf("\n"); int i,n; scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&st[i].x),st[i].id=i; sort(st+1,st+n+1); memset(map,0,sizeof(map)); bool flag=1; for(i=1;i<n;i++) { for(int j=1;j<=st[i].x;j++) { st[i+j].x--; if(st[i+j].x<0) { flag=0; break; } map[st[i].id][st[i+j].id]=1; map[st[i+j].id][st[i].id]=1;//printf("%d %d ",i,j); } if(flag==0) break; sort(st+i+1,st+n+1); } if(flag) { int j; printf("YES\n"); for(i=1;i<=n;i++) { for(j=1;j<n;j++) printf("%d ",map[i][j]); printf("%d\n",map[i][j]); } } else printf("NO\n"); } return 0; }
  • 相关阅读:
    springMVC的自定义类型的转换器
    pl/sql
    oracle中的函数
    Oracle基础
    跳台阶算法题
    红黑树
    优先队列
    堆排序
    H5页面,输入框的光标,如果页面上下滑动光标停留在页面上,除了输入框外,松手过了一段时间才跑回输入框里面
    正则:判断为数字,输入的金额整数位不得超过9位,小数位不得超过2位!
  • 原文地址:https://www.cnblogs.com/372465774y/p/2754348.html
Copyright © 2011-2022 走看看