2014辽宁省赛 Traveling

79 篇文章 0 订阅

问题 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<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int MAX=10005;
int f[MAX];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<n;i++)
        {
            scanf("%d",&f[i]);
        }
        bool flag=true;
        for(int i=0;i<n;i++)
        {
            int p=i+1;
            while(f[i]>0&&p<n)
            {
                if(f[p++]>0)
                {
                    f[p-1]--;
                    f[i]--;
                }
            }
            if(f[i]!=0)
            {
                cout<<"NO"<<endl;
                flag=false;
                break;
            }
        }
        if(flag)
        {
            cout<<"YES"<<endl;
        }
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值