Traveling
Problem J: Traveling
Time Limit: 1 Sec Memory Limit: 32 MB
Description
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.
Input
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.
Output
If a group of data is correct, output "YES" in one line, otherwise, output "NO".
Sample Input
8
7 7 4 3 3 3 2 1
10
5 4 3 3 2 2 2 1 1 1
Sample Output
NO
YES
上代码
#include<stdio.h>
int a[];
int main(){
int n,i,j,flag;
while(~scanf("%d",&n))
{
flag=;
for(i=;i<n;i++)
scanf("%d",&a[i]);
for(i=;i<n;i++)
{
for(j=i+;j<n;j++)
{
if(a[i]&&a[j]){
a[i]--;
a[j]--;
}
}
if(a[i]!=)
{
printf("NO\n");
flag=;
break;
}
}
if(flag) printf("YES\n");
}
return ;
}
/**************************************************************
Problem: 10
User: Hui
Language: C
Result: Accepted
Time:100 ms
Memory:1012 kb
****************************************************************/
Traveling的更多相关文章
- Traveling in Blade & Soul
Traveling in Blade & Soul Walking is too simple. Having trained their physics and spirits for ye ...
- UESTC 1852 Traveling Cellsperson
找规律水题... Traveling Cellsperson Time Limit: 1000ms Memory Limit: 65535KB This problem will be judged ...
- Traveling by Stagecoach 状态压缩裸题
Traveling by Stagecoach dp[s][v] 从源点到达 v,状态为s,v的最小值. for循环枚举就行了. #include <iostream> #inclu ...
- poj2686 Traveling by Stagecoach
http://poj.org/problem?id=2686 Trav ...
- 旅行商问题(Traveling Salesman Problem,TSP)的+Leapms线性规划模型及c++调用
知识点 旅行商问题的线性规划模型旅行商问题的+Leapms模型及CPLEX求解C++调用+Leapms 旅行商问题 旅行商问题是一个重要的NP-难问题.一个旅行商人目前在城市1,他必须对其余n-1个城 ...
- Complexity and Tractability (3.44) - The Traveling Salesman Problem
Copied From:http://csfieldguide.org.nz/en/curriculum-guides/ncea/level-3/complexity-tractability-TSP ...
- Speeding Up The Traveling Salesman Using Dynamic Programming
Copied From:https://medium.com/basecs/speeding-up-the-traveling-salesman-using-dynamic-programming-b ...
- Codeforces Round #304 (Div. 2) E. Soldier and Traveling 最大流
题目链接: http://codeforces.com/problemset/problem/546/E E. Soldier and Traveling time limit per test1 s ...
- 【智能算法】用模拟退火(SA, Simulated Annealing)算法解决旅行商问题 (TSP, Traveling Salesman Problem)
喜欢的话可以扫码关注我们的公众号哦,更多精彩尽在微信公众号[程序猿声] 文章声明 此文章部分资料和代码整合自网上,来源太多已经无法查明出处,如侵犯您的权利,请联系我删除. 01 什么是旅行商问题(TS ...
随机推荐
- CentOS mini版安装后增加gcc编译环境
使用如下命令即可: sudo yum install gcc gcc-c++ make -y
- HOOK钩子 - 钩子函数说明
翻译参考自MaybeHelios的blog: http://blog.csdn.net/maybehelios/ 通过SetWindowsHookEx方法安装钩子,该函数指定处理拦截消息的钩子函数(回 ...
- WebApp开发技巧大全 看了就明白了
[转载]阅读原文 自Iphone和Android这两个牛逼的手机操作系统发布以来,在互联网界从此就多了一个新的名词-WebApp(意为基于WEB形式的应用程 序,运行在高端的移动终端设备).开发者们都 ...
- jquery中的全局事件
ajaxStart(callback):Ajax请求开始时触发该事件 ajaxSend(callback):Ajax请求发送前触发该事件 ajaxSuccess(callback):Ajax请求成功时 ...
- Java 中使用Jackson反序列化
Build.gradle: compile group: 'org.codehaus.jackson', name: 'jackson-mapper-lgpl', version: '1.9.13' ...
- unigui数据库连接池
UNIGUI for delphi,是一款WEB RIA开发框架.开发WEB程式如传统C/S般简单,众多DELPHIER趋之若鹜. 虽然上手非常容易,但要真正使用好,有些地方还是值得考究的. 网上有同 ...
- 第二章 andrid studio创建项目
原文 http://blog.csdn.net/zhanghefu/article/details/9326735 第二章 andrid studio创建项目 第二章 andrid studio创建项 ...
- CentOS安装与配置LNMP
本文PDF文档下载:http://www.coderblog.cn/doc/Install_and_config_LNMP_under_CentOS.pdf 本文EPUB文档下载:http://www ...
- ceph rpm foor rhel6
ceph-0.86-0.el6.x86_64.rpm 09-Oct-2014 10:00 13M ceph-0.87-0.el6.x86_64.rpm 29-Oct-2014 13:38 13M ce ...
- wx.Notebook
wx.Notebook This class represents a notebook control, which manages multiple windows with associated ...