• 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
    ");
                    flag=0;
                    break;
                }
            }
            if(flag) printf("YES
    ");
        }
        return 0;
    } 
     
    /**************************************************************
        Problem: 10
        User: Hui
        Language: C
        Result: Accepted
        Time:100 ms
        Memory:1012 kb
    ****************************************************************/
  • 相关阅读:
    一本通1281:最长上升子序列 暨 LIS DP求解
    STL初步
    【洛谷P3369】【模板】普通平衡树
    【洛谷P4859】已经没有什么好害怕的了
    【CF961G】Partitions
    【洛谷P4718】【模板】Pollard-Rho算法
    【LOJ#143】质数判定
    【CF917D】Stranger Trees
    【洛谷P3700】小Q的表格
    【洛谷P4245】【模板】任意模数多项式乘法
  • 原文地址:https://www.cnblogs.com/suthui/p/3816305.html
Copyright © 2020-2023  润新知