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[12345];

int main(){
    int n,i,j,flag;
    while(~scanf("%d",&n))
    {
        flag=1;
        for(i=0;i<n;i++)
            scanf("%d",&a[i]);
        for(i=0;i<n;i++)
        {
            for(j=i+1;j<n;j++)
            {
                if(a[i]&&a[j]){
                    a[i]--;
                    a[j]--;
                }
            }
            if(a[i]!=0)
            {
                printf("NO\n");
                flag=0;
                break;
            }
        }
        if(flag) printf("YES\n");
    }
    return 0;
} 

/**************************************************************
    Problem: 10
    User: Hui
    Language: C
    Result: Accepted
    Time:100 ms
    Memory:1012 kb
****************************************************************/

Traveling,布布扣,bubuko.com

时间: 2024-12-28 15:53:10

Traveling的相关文章

CodeForces 21D Traveling Graph 状压dp+欧拉回路

题目链接:点击打开链接 题意: 给定n个点m条边的无向图 求从1点开始经过每条边至少一次最后回到1点的最小路程 显然就是找一条路径可重复的欧拉回路 思路: 首先对于欧拉回路的结论是:所有点的度数都为偶数 因为所有边至少经过一次,那么可以把题意转换成加最少多少条边使得图满足以上结论 而加的边目的是为了把奇度数转成偶度数,先floyd一下得到任意点间加边的最小花费 dp[i]表示状态i下度数都为偶数的最小花费. 状压dp,把i状态下,所有未选择的点中挑2个奇度数的转移即可. #include <cs

2014辽宁省赛 Traveling

问题 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 

poj2686 Traveling by Stagecoach

http://poj.org/problem?id=2686 Traveling by Stagecoach Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 2276   Accepted: 787   Special Judge Description Once upon a time, there was a traveler. He plans to travel using stagecoaches (horse

POJ 2686 Traveling by Stagecoach(状压二维SPFA)

Traveling by Stagecoach Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3407   Accepted: 1322   Special Judge Description Once upon a time, there was a traveler. He plans to travel using stagecoaches (horse wagons). His starting point an

HIT2372 Recoup Traveling Expenses(最长单调子序列)

题目链接: http://acm.hit.edu.cn/hoj/problem/view?id=2372 题目描述: Recoup Traveling Expenses Submitted : 206, Accepted : 102 A person wants to travel around some places. The welfare in his company can cover some of the airfare cost. In order to control cost,

poj 2686 Traveling by Stagecoach

Traveling by Stagecoach Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3293   Accepted: 1253   Special Judge Description Once upon a time, there was a traveler. He plans to travel using stagecoaches (horse wagons). His starting point an

Traveling 【图的性质】

Traveling 时间限制: 1 Sec 内存限制: 32 MB 提交: 41 解决: 23 [提交][状态][讨论版] 题目描述 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 mainl

Codeforces Round #304 (Div. 2) E. Soldier and Traveling 最大流 Dinic EK 算法

E. Soldier and Traveling time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output In the country there are n cities and m bidirectional roads between them. Each city has an army. Army of the i-th ci

P2 speech-my traveling experience

My traveling experience Traveling makes my life to be colorful at the same time I become optimistic and learning to know about other people ideas. Certainly, During the traveling not only I had lived through happy things, but also I had painful exper