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

在线体验各类最新模型,更有模型 免费Token 额度领取!
立即体验
简介: 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;
}
目录
相关文章
2018ICPC青岛站 D . Magic Multiplication(构造 模拟)
2018ICPC青岛站 D . Magic Multiplication(构造 模拟)
193 0
|
机器学习/深度学习 算法 Java
HDU - 2018杭电ACM集训队单人排位赛 - 3 - Problem B. Bullet
HDU - 2018杭电ACM集训队单人排位赛 - 3 - Problem B. Bullet
345 0
|
人工智能 Java
HDU - 2018杭电ACM集训队单人排位赛 - 2 - Problem C. Team Match
HDU - 2018杭电ACM集训队单人排位赛 - 2 - Problem C. Team Match
286 0
|
5天前
|
缓存 人工智能 安全
GPT-5.6 Terra与GPT-5.5性能实测:成本减半后的跑分对比与快速迁移指南
GPT-5.6 Terra 的定价为每百万 token 输入 2.50/输出 15。GPT-5.5 则是 5/ 30。Terra 的每一项费率,包括 $0.25/M 的缓存读取,都恰好是 GPT-5.5 的一半,因此在任何工作负载组合下,Terra 都固定 便宜 2.0x。以每天 10 万次请求、3K token 提示词计算,大约是 Terra 每天 2,000,GPT−5.5每天 4,000,即每月约 60,000对 120,000。问题在于:OpenAI 没有发布任何针对 Terra 的编码基准。那个著名的 91.9% Terminal-Bench 数字是 Sol 在 Ul
|
12天前
|
存储 关系型数据库 MySQL
云数据库自研存储引擎:阿里云 PolarDB 相比开源 MySQL 性能提升数倍
云数据库自研存储引擎已成为云原生数据库竞争的核心技术高地。阿里云 PolarDB 通过 X-Engine 高压缩存储、PolarStore 用户态 IO + RDMA、IMCI 列存 HTAP 三大自研引擎组合,配合物理日志、跨节点 Buffer Pool 共享、Parallel Query 五大优化,实现写性能 6 倍、压缩 3-5 倍、AP 加速 100 倍、IO 延迟 -80% 的全面超越,让客户存储成本下降 65%、DBA 人力节省 80%。
454 114
|
5天前
|
人工智能 缓存 JSON
刚刚 GPT-5.6 发布,吊打 Claude 5 和 Grok 4.5?一手实测来啦!
GPT-5.6 刚发布,跑分号称超越 Fable 5,真的假的?附一手实测,让 3 个最强 AI 编程模型 GPT-5.6 Sol、Claude Fable 5、Grok 4.5 在 Cursor 里同时一把梭开发网页游戏,看看最新模型到底谁更能打。
312 0
|
5天前
|
存储 人工智能 JSON
Qwen 本地部署搭配 ComfyUI 生成 AI 漫剧完整实操指南(小白零基础可落地,零成本无限生成+角色一致性天花板)
2026全网最优本地漫剧流水线:零成本、离线运行、角色统一、低配(8G显卡)可跑。融合Qwen本地大模型+ComfyUI双引擎,实现剧本生成→分镜绘图→动态成片全自动,隐私安全、无审核限流,新手30分钟上手,日更无忧。(239字)