程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> 2014遼寧省賽 Traveling

2014遼寧省賽 Traveling

編輯:C++入門知識

問題 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 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.

輸入

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.

輸出

If a group of data is correct, output "YES" in one line, otherwise, output "NO".

樣例輸入

8 7 7 4 3 3 3 2 1 10 5 4 3 3 2 2 2 1 1 1

樣例輸出

NO YES

提示

這道題不難,數據范圍也不大,只需要進行過程的模擬,詳見代碼

#include
#include
#include
#include
#include
using namespace std;
const int MAX=10005;
int f[MAX];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i0&&p0)
                {
                    f[p-1]--;
                    f[i]--;
                }
            }
            if(f[i]!=0)
            {
                cout<<"NO"<

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved