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.

【题解】

题意:给出度的序列问是否存在符合的简单图。

思路:  需满足:1.奇数度节点的个数是偶数   2.每个节点度数不超过n-1

【代码】

#include<bits/stdc++.h>
using namespace std;
long long a[100005];
main()
{
   int t,n,i,j;
   scanf("%d",&t);
   while(t--)
   {
       memset(a,0,sizeof(a));
       scanf("%d",&n);
       for(i=0;i<n;i++)
           scanf("%lld",&a[i]);
       long long maxn=0,c=0;
       for(i=0;i<n;i++)
       {
           maxn=max(maxn,a[i]);
           if(a[i]%2)
            c++;
       }
       if(c%2==0&&maxn<n)
         printf("Y\n");
       else
         printf("N\n");
   }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值