首页 > 其他分享 >The 2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest

The 2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest

时间:2023-04-24 22:38:35浏览次数:55  
标签:Minh City cnt ch network int ACM rooms include


The tunnels of Cu Chi are an immense network of underground tunnels connecting rooms located in the Cu Chi District of Ho Chi Minh City. The Cu Chi tunnels were the location of several military campaigns in the 1960s. Nowadays, it is a popular tourist destination.

There are documents from trusted sources about a private network of tunnels in this area used by a secret forces unit but it has not been discovered. According to the documents, this private network has N rooms (numbered from 1 to N) connected by N−1 bidirectional tunnels. Room 1 is the entry point from the ground surface to this underground network. From room 1, you can follow the tunnels to go to any of the rooms. The rooms are numbered in such a way that, if you follow the shortest path from room 1 to any room X, the sequence of visited rooms’ indices will be increasing. The image below shows a valid map of this network.

\includegraphics[width=0.5\textwidth ]{example1.png}
The network below is invalid, since the path from 1 to 4 is 1 - 3 - 2 - 4, which is not increasing:

\includegraphics[width=0.5\textwidth ]{example2.png}
There is also an old article from an unknown source mentioning about Di which is the number of rooms directly connected to room i.

Given an array D of size N, your task is to verify if it is possible to have such a network.

Input
The first line contains an integer N - the number of rooms in the network (2≤N≤1000).

The second line consists of N integers Di - the number of rooms that are directly connected to room i (1≤Di≤N−1).

Output
Print YES/NO if it is possible/impossible to have such a network, respectively.

Sample Input 1 Sample Output 1
8
3 2 2 1 1 3 1 1
YES
Sample Input 2 Sample Output 2
4
3 3 3 3
NO

给定节点的度数,求是否存在节点递增的树存在
模拟即可;

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<string>
typedef long long ll;
using namespace std;
typedef unsigned long long int ull;
#define maxn 2000005
#define inf 0x3f3f3f3f
const long long int mod = 1e9 + 7;

ll read() {
    ll x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch>'9') {
        if (ch == '-') {
            f = -1;
        }
        ch = getchar();
    }
    while (ch >= '0'&&ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

ll quickpow(ll a, ll b) {
    ll ans = 1;
    while (b > 0) {
        if (b % 2)ans = ans * a%mod;
        b = b / 2;
        a = a * a%mod;
    }
    return ans;
}

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a%b);
}

ll ves[maxn];
void revs() {
    for (ll i = 1; i <= 1000000; i++) {
        ves[i] = quickpow(i, mod - 2);
    }
}


//ull Mod = quickpow(2ull, 47ull);
int a[maxn];
int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int i;
    int tot = 0;
    for (i = 1; i <= n; i++) {
        cin >> a[i];
        tot += a[i];
    }
    int cnt = 0;
    int  flag = 0;
    if (tot % 2 == 0 && tot / 2 == n - 1) {
        for (i = n; i >= 1; i--) {
            if (i == 1) {
                cnt -= a[i];
            }
            else if (a[i] != 1 && i != 1) {
                if (cnt < a[i] - 1) {
                    flag = 1;
                    break;
                }
                cnt -= a[i] - 2;
            }
            else cnt++;
        }
        if (flag == 1 || cnt < 0)cout << "NO" << endl;
        else cout << "YES" << endl;
    }
    else cout << "NO" << endl;
    return 0;
}


标签:Minh,City,cnt,ch,network,int,ACM,rooms,include
From: https://blog.51cto.com/u_15657999/6221929

相关文章

  • ACM International Collegiate Programming Contest 2014 B SPFA 统计路径
    FloweryTrails!”()”*+,-).%”/)’0”122”1!2”342”522”!22”652”!42”72”72”5!2”!12”622”18!”162”!12”6”7”4”9”3”5”8”1”2”Inordertoattractmorevisitors,themanagerofanationalp......
  • ACM International Collegiate Programming Contest 2014 A dfs 好题
    GREAT+SWERC=PORTOWewanttohaveagreatSWERCatPortothisyearandweapproachedthischallengeinseveralways.Weevenframeditasawordadditionproblem,similartotheclassicSEND+MORE=MONEY,whereeachletterstandsforasingledigit(......
  • codeforces 414B B. Mashmokh and ACM(dp)
    题目链接:codeforces414B题目大意:定义一个序列,前一项能够整除后一项,给定这个序列中数的取值范围和序列的长度,问有多少种构造方法。题目分析:我们定义状态dp[i][j]为前i项已经确定且第i项为j的方案数。转移方程dp[i][j]=∑k|jdp[i−1][k]复杂度O(n⋅k)AC代码:#include<iostream>......
  • 跑路资金盘偷偷复活!西城威尔士City Wealth卷土重来!注意警惕!
    野火烧不尽,春风吹又生...这就是黑平台的真实写照,很多资金盘或者黑平台,在被曝光或者钱收割的差不多的时候,都会选择跑路,而跑路之后呢?你以为就此收手了吗?!并不是!实际上贪心才是人之本性,一般黑平台跑路之后,要么是换个名字继续割韭菜,要么就是静悄悄的卷土回归敛财。还记得之前在汇圈闹得......
  • 【ACM算法竞赛日常训练】DAY16【奇♂妙拆分】【区区区间间间】【小AA的数列】数学 |
    DAY16共3题:奇♂妙拆分(简单数学)区区区间间间(单调栈)小AA的数列(位运算dp)......
  • 【ACM组合数学 | 错排公式】写信
    题目链接:https://ac.nowcoder.com/acm/contest/54484/B题意很简单,但是数据范围偏大。错排公式首先来推导一下错排公式:$$D(n)=n!\sum_{k=0}^{n}\frac{(-1)^k}{k!}$$设一个函数:$$S_i表示一个排列中p_i=i的方案数$$那么我们可以知道:$$D(n)=n!-|\cup_{i=1}^{n}S_i|$$......
  • 【ACM组合数学 | 错排公式】写信
    题目链接:https://ac.nowcoder.com/acm/contest/54484/B题意很简单,但是数据范围偏大。错排公式首先来推导一下错排公式:\[D(n)=n!\sum_{k=0}^{n}\frac{(-1)^k}{k!}\]设一个函数:\[S_i表示一个排列中p_i=i的方案数\]那么我们可以知道:\[D(n)=n!-|\cup_{i=1}^{n}S_i|\]......
  • pacman使用
    //安装包pacman-Sboost-libs//卸载包pacman-Rsboost-libs//显示包版本pacman-Qboost-libs#Displayversion//显示包安装的文件详细列表pacman-Qlboost-libs#Displayfilelistprovidedbylocalpackage//显示包缺失的文件pacman-Qkboost-libs#Checkthel......
  • 电子科技大学第二十一届ACM程序设计竞赛 决赛游记
    Preface第一次线下组队打ACM比赛,算是次很难忘的经验吧昨天晚上和队友才第一次在食堂见面,然后简单交流了下今天的策略方针等其实大部分时间还是在扯皮,没想到刚好三个key厨组成了一队,早知道队名就叫HellBurnsGreen了然后关于赛前,今天早上还算起的挺早,然后不知道干什么就去学校的......
  • 猫猫军阀和它的小犬_acm大陆的游玩记录
    这里是猫猫军阀和它的小犬(也就是我,liyishui)一起在acm大陆游玩的记录。在我们想一起做的所有事情里,一起去骑行,爬雪山,露营,公益,写代码,为了小猫能攒够毕业学分一起参加数模,一起学习..有一天小猫说想陪我打比赛然后就有了后来:D Day1#牛客小白月赛70,小猫做了abc,我去看了篮球赛......