2014辽宁省赛 Traveling
来源:互联网 发布:淘宝黑号洗白教程 编辑:程序博客网 时间:2024/09/21 08:56
问题 K: Traveling
时间限制: 1 Sec 内存限制: 128 MB
提交: 13 解决: 4
[提交][状态][论坛]
题目描述
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<iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<cmath>using namespace std;const int MAX=10005;int f[MAX];int main(){ int n; while(scanf("%d",&n)!=EOF) { for(int i=0;i<n;i++) { scanf("%d",&f[i]); } bool flag=true; for(int i=0;i<n;i++) { int p=i+1; while(f[i]>0&&p<n) { if(f[p++]>0) { f[p-1]--; f[i]--; } } if(f[i]!=0) { cout<<"NO"<<endl; flag=false; break; } } if(flag) { cout<<"YES"<<endl; } } return 0;}
- 2014辽宁省赛 Traveling
- 2014辽宁省赛 Repeat Number
- 2014年辽宁省赛 distance
- 2014辽宁省赛 Picking Cabbage 状压dp
- 2014辽宁省省赛 luckly number
- 2014ACM辽宁省赛Prime Factors
- 辽宁省赛2010
- 辽宁省赛总结
- 辽宁省赛2010
- 辽宁省赛2010 G
- 2014辽宁省ACM程序设计大赛网络赛 Problem A: Decryption
- neu1482 2014辽宁省赛Picking Cabbage(状态压缩)
- 2012.6辽宁省赛 Problem F
- 2010 辽宁省省赛 题解
- 忆2015年辽宁省赛
- Friends number 2010辽宁省赛
- Traveling
- Traveling
- 计数排序
- 在一般处理程序里写一个简单验证码
- 常见浏览器兼容性问题与解决方案
- hdu2201
- Mac系统的操作技巧
- 2014辽宁省赛 Traveling
- 软件界面设计
- PHP的mysqli扩展
- Cocos2d-x 3.0心得(03)-CocosBuilder扩展自定义参数
- php不能加载mssql扩展解决办法
- 2014百度之星资格赛——XOR SUM
- 添加Visual studio 2010 Command Prompt
- 软件工程(学科)
- 2014辽宁ACM省赛 Distance