HDU 6029 Graph Theory

题意:有n个点,对于每个点有两种操作,(1)  跟他之前的点都连一条边。(2) 不做操作。现在对于每个点都给定了操作,问能否从中选取几条边,每条边都没有公共端点,而且n个点都被边覆盖。


分析:首先,很容易想到,当n为奇数的时候,答案肯定是No。

  然后是偶数,取一个cnt表示到当前,前面还有几个点没有连边,for一遍就好。


以下是代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstring>
#include<string>
#include<vector>
#include<iomanip>
//#include<unordered_set>
//#include<unordered_map>
#include<cmath>
#include<list>
#include<bitset>
using namespace std;
#define _____ ios::sync_with_stdio(false); cin.tie(0);
#define ull unsigned long long
#define ll long long
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1

typedef pair<int, int>pii;
typedef pair<ll, ll>pll;
typedef pair<double, double>pdd;
const double eps = 1e-6;
const int MAXN = 100005;
const int MAXM = 5005;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const double FINF = 1e18;
const ll MOD = 1000000007;
int a[100005];
int main()
{
    int t,n;
    scanf("%d", &t);
    while (t--)
    {
        scanf("%d", &n);
        if (n % 2 == 1)
        {
            for (int i = 2; i <= n; ++i)scanf("%d", &a[i]);
            printf("No\n");
        }
        else
        {
            int cnt = 1;
            bool flag = 1;
            for (int i = 2; i <= n; ++i)
            {
                scanf("%d", &a[i]);
                if (a[i] == 1)
                {
                    if (cnt == 0)cnt = 1;
                    else cnt--;
                }
                else cnt++;
            }
            if (cnt > 0)printf("No\n");
            else printf("Yes\n");
        }

    }
}





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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值