Traveling 【图的性质】
来源:互联网 发布:淘宝第一层级什么意思 编辑:程序博客网 时间:2024/05/16 14:29
Traveling
时间限制: 1 Sec 内存限制: 32 MB
提交: 41 解决: 23
[提交][状态][讨论版]
题目描述
SH likes traveling around the world. When he arrives at a city, he will ask the staff about the number of cities that connected with this city directly. After traveling around a mainland, SH will collate data and judge whether the data is correct.
A group of data is correct when it can constitute an undirected graph.
输入
There are multiple test cases. The first line of each test case is a positive integer N (1<=N<=10000) standing for the number of cities in a mainland. The second line has N positive integers a1, a2, …,an. ai stands for the number of cities that connected directly with the ith city. Input will be ended by the END OF FILE.
输出
If a group of data is correct, output “YES” in one line, otherwise, output “NO”.
样例输入
8
7 7 4 3 3 3 2 1
10
5 4 3 3 2 2 2 1 1 1
样例输出
NO
YES
#include <stdio.h>#include <iostream>#include <string.h>#include <algorithm>#include <math.h>#include <ctype.h>#include <time.h>#include <queue>using namespace std;const int MAXN =10010;int p[MAXN];int n;int solve (){ for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { if (p[i]>0 && p[j] >0) { p[i]-- ; p[j]--; } } if (p[i]!=0) { return 0; } } return 1;}int main(){ while (scanf("%d",&n)!=EOF) { for(int i=0;i<n;i++) scanf("%d",&p[i]); if (solve()) printf("YES\n"); else printf("NO\n"); } return 0;}
- Traveling 【图的性质】
- CodeForces 21D - Traveling Graph 欧拉回路的性质+状态压缩DP
- 二分图的性质
- 图的重要性质
- 二分图的性质
- Traveling
- Traveling
- HDU2454 图的基本性质
- 二分图的一些性质
- 图的概念及性质
- hdu 3118 Arbiter 二分图的性质
- hdu 2454 简单图性质的运用
- hdu3118二分图性质的应用
- HDU3478 【判奇环/二分图的性质】
- 文字性质的CSS
- c++的重要性质
- 多叉树的性质
- sinc函数的性质
- HDFS-2.0社区版的HA+Federation的实现解析
- Vim 多窗口操作
- 公务员考试布局
- Android项目实战经验总结
- 无聊之作 对 手游十万个为什么(神之刃) 的解包分析笔记 (游戏引擎)
- Traveling 【图的性质】
- UNIX环境高级编程---读后感
- 猫猫学IOS(十三)UI之UITableView学习(下)汽车名牌带右侧索引
- java Socket笔记
- CSS中的绝对定位与相对定位
- 第三周项目:考了语文数学的学生
- 大话桶排序 基数排序和计数排序
- 游戏开发算法(二)
- WindowManager$BadTokenException: Unable to add window -- token null is not for an appl