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 ...
随机推荐
- jvm强制类型转换
public class Integer_Object { public static void main(String[] args){ Object obj = new ooo(); // Int ...
- jquery 获取select选中的值
获取选中的名称:$("#selectPinType option:selected").text(); 获取选中的值:$("#selectPinType option:s ...
- ajax中返回包含html的奇葩问题
如果通过ajax返回一串包含有html标签的字符串,然后添加到相应的html文档位置,如果标签外含有空格或者换行等就会报错.
- Android 不通过USB数据线调试的方法
在开发Android应用时,通常情况下是通过USB数据线连接设备和计算机,但对于一些需要使用USB设备的应用,这种方法就碰到了麻烦,手机的USB接口已经和外接的USB设备连接,无法再连数据线,此时可以 ...
- Python中关于try...finally的一些疑问
最近看Vamei的Python文章,其中一篇讲异常处理的,原本看完没啥疑惑,或许是自己想的简单了. 看到评论,一个园友的问题引起我的兴趣. 他的问题是 def func(x): try: return ...
- PDO的事物处理机制
Mysql的事务处理: 1.MySQL目前只有InnoDB 和BDB两个数据表类型才支持事务. 2.在默认条件下,MySQL是以自动提交(autocommit)模式运行的,这就意味着所执行的每一个语句 ...
- Flink Program Guide (6) -- 窗口 (DataStream API编程指导 -- For Java)
窗口(Window) 本文翻译自文档Windows ----------------------------------- Flink使用窗口的概念,根据element的时间戳或者其他指标,将可能无限 ...
- c语言字符串翻转系列
2013-10-25 最近碰到一道笔试题,是关于字符串翻转的.题目是:将一段英文翻转,但保留单词拼写,如给定字符串str="I am a student",返回为"stu ...
- 二维树状数组(HD2642)
#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<stdio.h> #include<string. ...
- lua学习笔记(1)-基本语法
==============变量类型nilnumber(实数) 1 2 3.14 7.65e8string "hello world" "\n ...