HDU - 2018杭电ACM集训队单人排位赛 - 4 - Problem C. Sequence

简介: HDU - 2018杭电ACM集训队单人排位赛 - 4 - Problem C. Sequence

C — Sequence

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 0    Accepted Submission(s): 0


Problem Description


As we all know, Sister Ye is good at Graph Theory. Now he is intending to examine your Graph Theory level. Sister Ye would show you a degree sequence and ask you to find a simple graph that satisfies the sequence of degrees. Because the graph may be too large, you have to answer if such a graph exists or not only. In order to prevent you from guessing, Sister Ye will ask you more than once.


Input


The first line contains an integer T, the times Sister Ye ask you.


Each question will begin with a line contains an integer n, the size of sequence.

The following line contains a degree sequence a1,...,an.


Output


You should answer 'Y'(yes) or 'N'(no) for each question in one line.

1 ≤ T ≤ 50.

1 ≤ n ≤ 100000.

1 ≤ ai ≤ 10^9.


Sample Input

2

1

1

3

2 1 1


Sample Output

N

Y



Hint

loop:a loop is an edge that connects a vertex to itself.

simple graph: a graph without loops and multiple edges between two vertexes.

degree:the degree of a vertex in a graph is the number of edges connected to the vertex.

degree sequence: An integer sequence of the degrees for each vertex in the graph.


解题思路:给定一组节点的度序列来判断一个图是否为简单图?(符合以下两点即可)


每个节点度数要小于节点个数

该图具有偶数个奇数度的节点

AC 代码


#include<bits/stdc++.h>
#include<cmath>
#define mem(a,b) memset(a,b,sizeof a);
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn=100010;
int n,a[maxn];
bool ok()
{
    int sum=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]%2==1) sum++;
        if(a[i]>=n) return 0;
    }
    if(sum%2==1) return 0;
    return 1;
}
int main()
{
    int T; scanf("%d",&T);
    while(T-- && ~scanf("%d",&n))
    {
        for(int i=0;i<n;i++) scanf("%d",&a[i]);
        puts(ok()?"Y":"N");
    }
    return 0;
}
目录
相关文章
2022天梯赛三月冲刺——PAT (Advanced Level)1013 Battle Over Cities (并查集找连通块)
2022天梯赛三月冲刺——PAT (Advanced Level)1013 Battle Over Cities (并查集找连通块)
116 0
|
机器学习/深度学习 Web App开发 人工智能
7 Papers & Radios | 中国天眼FAST登Nature封面;MIT提出可出题、做题、评分模型(2)
7 Papers & Radios | 中国天眼FAST登Nature封面;MIT提出可出题、做题、评分模型
265 0
|
机器学习/深度学习 人工智能 自然语言处理
7 Papers & Radios | 中国天眼FAST登Nature封面;MIT提出可出题、做题、评分模型(1)
7 Papers & Radios | 中国天眼FAST登Nature封面;MIT提出可出题、做题、评分模型
139 0
[SDUT 2414] | 山东省第三届省赛 An interesting game | 最小费用最大流
题目描述 Xiao Ming recently designs a little game, in front of player there are N small hillsides put in order, now Xiao Ming wants to increase some hillsides to block the player, so he prepared another M hillsides, but he does not hope it will be too difficult,
166 0
[SDUT 2414] | 山东省第三届省赛 An interesting game | 最小费用最大流
2019牛客暑期多校2-Partition problem深搜
题意: 将2*n个人分成两部分,每部分都有n个人 而且每个人只能属于一个组,问按照给出的算式得到的竞争力最大值是多少
97 0
2019牛客暑期多校2-Partition problem深搜
|
人工智能 Java
HDU - 2018杭电ACM集训队单人排位赛 - 3 - Problem E. Sequence
HDU - 2018杭电ACM集训队单人排位赛 - 3 - Problem E. Sequence
154 0
|
Java
HDU - 2018杭电ACM集训队单人排位赛 - 3 - Problem F. Four-tuples
HDU - 2018杭电ACM集训队单人排位赛 - 3 - Problem F. Four-tuples
144 0
|
人工智能 Java
HDU - 2018杭电ACM集训队单人排位赛 - 4 - Problem J. number sequence
HDU - 2018杭电ACM集训队单人排位赛 - 4 - Problem J. number sequence
139 0
|
机器学习/深度学习 算法 Java
HDU - 2018杭电ACM集训队单人排位赛 - 3 - Problem B. Bullet
HDU - 2018杭电ACM集训队单人排位赛 - 3 - Problem B. Bullet
173 0
|
Java Go
HDU - 2018杭电ACM集训队单人排位赛 - 2 - Problem E. Travel
HDU - 2018杭电ACM集训队单人排位赛 - 2 - Problem E. Travel
128 0