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 ...
随机推荐
- J2EE监听器和过滤器基础
Servlet程序由Servlet,Filter和Listener组成,其中监听器用来监听Servlet容器上下文. 监听器通常分三类:基于Servlet上下文的ServletContex监听,基于会 ...
- 如何在linux中设置tab键长度
1. 创建文件名为 .vimrc 的系统文件 首先切换到用户根目录,然后创建文件. $ cd ~ $ vim .vimrc 2. 在文件中输入下面的内容并保存 set tabstop=4 set sh ...
- html 中head显示 在标题栏里面的图片
在<head>标签里加<link rel="Shortcut Icon" href="你的ico图片地址" /> 一般标题栏里的图片是1 ...
- python基础教程
转自:http://www.cnblogs.com/vamei/archive/2012/09/13/2682778.html Python快速教程 作者:Vamei 出处:http://www.cn ...
- CentOS 7 上搭建LNMP环境
(转自美团云知识库Chris) 简介 LNMP是Linux.Nginx.MySQL(MariaDB)和PHP的缩写,这个组合是最常见的WEB服务器的运行环境之一.本文将带领大家在CentOS 7操作系 ...
- 对discuz的代码分析学习(四)论坛入口文件
只是大致分析下执行流程,主要就是取得mod参数的值,根据取值加载控制器,控制器位置在最后一行指定了. 1 )定义应用名称,加载两个必要文件 define('APPTYPEID', 2); define ...
- mongo设计(二)
原文:http://blog.mongodb.org/post/87892923503/6-rules-of-thumb-for-mongodb-schema-design-part-2 By Wil ...
- 1016. 部分A+B
/* * Main.c * 1016. 部分A+B * Created on: 2014年8月30日 * Author: Boomkeeper *******测试通过********* */ #inc ...
- Array 的五种迭代方法 -----every() /filter() /forEach() /map() /some()
ES5定义了五个迭代方法,每个方法都接收两个参数:要在每一项上运行的函数和运行该函数的作用域对象(可选的),作用域对象将影响this的值.传入这些方法中的函数会接收三个参数:数组的项的值.该项在数组中 ...
- 处理json中的异常字符
在很多场景中需要通过json传递数据,如果json中包含英文的",""'"之类的字符,会导致json解析失败 可以用一些在线的json格式检查网站检查是否含有异 ...