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 ...
随机推荐
- IIS出现Server Application Unavailable的解决办法
在XP中IIS5.1服务器,运行asp.net出现Server Application Unavailable,经过多次查证,才发现是因为先安装了.net Framework 2.0然后安装IIS,导 ...
- char varchar varchar2 的区别 (转)
char varchar varchar2 的区别 http://blog.csdn.net/honglei_zh/article/details/7172538区别:1.CHAR的长度是 ...
- C#高效分页代码(不用存储过程)
首先创建一张表(要求ID自动编号): create table redheadedfile ( id ,), filenames ), senduser ), primary key(id) ) 然后 ...
- 菜鸟的jQuery源码学习笔记(三)
each: function(callback, args) { return jQuery.each(this, callback, args); }, each:这个调用了jQuery.each方 ...
- PS切图保存后的背景图为透明
1.若想PS切图保存后的背景图为透明,那么则需要在如下图中所示的修改即可,切图后[文件]——>[存储为web格式]——>[PNG-24]: 2.要想在css中的背景图片为相通,则先剪切一个 ...
- 模拟app上商品详情点击图片放大并且可以切换大图
主要使用swiper插件,这里使用各小技巧,就是用两个swiper容器,点击一个小图容器,去让大图容器展示出来 小图容器 <div class="q_banner"> ...
- Android技术宅:自制USB OTG数据线
作为一名Android技术宅,USB OTG是你必须了解的,所谓USB OTG就是你可以利用手机或平板上用来充电.与电脑传输数据的micro USB接口来连接其他USB外设,如游戏手柄.鼠标.键盘.U ...
- Android Studio优化之启用Shift+Ctrl+O导入所有的包
在使用Eclipse开发Android应用时,开发者往往会使用Shift+Ctrl+O快捷键来快速导入所有的包,和移除已经导入但还未使用的包.但这个快捷键在Android Studio没人是给有开启的 ...
- 图片裁剪:CropZoom插件
上传个人头像的功能:用户在上传自己的照片后,由于照片尺寸不符合网站的要求,要求用户对照片进行裁剪,最终根据用户裁剪的尺寸生成头像. 用户可以对上传的图片进行自由缩放.裁剪,使之符合彩信图片的大小. C ...
- Mina入门:Java NIO基础概念
JDK1.4引入了Java NIO API(Java New IO),Java NIO得到了广泛应用.NIO允许程序进行非阻塞IO操作.java.nio.* 包括以下NIO基本结构: Buffer - ...