zoukankan      html  css  js  c++  java
  • 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
    ****************************************************************/
  • 相关阅读:
    pycharm上传代码到github中
    requests的封装(user-agent,proxies)
    Flask
    CTBCMCLibUser类
    TB timer 的用法
    多个 additional include directories 的复制方法
    怎样在编译时不显示警告
    infragistics 循环每一个选中的行
    Infragitics ultra grid 实现点击某一个cell的时候选中整行,并且不可编辑
    c#转换 datetime
  • 原文地址:https://www.cnblogs.com/suthui/p/3816305.html
Copyright © 2011-2022 走看看