传送门
题面:

Graph Theory

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1220    Accepted Submission(s): 553

Problem Description
Little Q loves playing with different kinds of graphs very much. One day he thought about an interesting category of graphs called ``Cool Graph'', which are generated in the following way:
Let the set of vertices be {1, 2, 3, ..., n}. You have to consider every vertice from left to right (i.e. from vertice 2 to n). At vertice i, you must make one of the following two decisions:
(1) Add edges between this vertex and all the previous vertices (i.e. from vertex 1 to i−1).
(2) Not add any edge between this vertex and any of the previous vertices.
In the mathematical discipline of graph theory, a matching in a graph is a set of edges without common vertices. A perfect matching is a matching that each vertice is covered by an edge in the set.
Now Little Q is interested in checking whether a ''Cool Graph'' has perfect matching. Please write a program to help him.
Input
The first line of the input contains an integer T(1≤T≤50), denoting the number of test cases.
In each test case, there is an integer n(2≤n≤100000) in the first line, denoting the number of vertices of the graph.
The following line contains n−1 integers a2,a3,...,an(1≤ai≤2), denoting the decision on each vertice.
Output
For each test case, output a string in the first line. If the graph has perfect matching, output ''Yes'', otherwise output ''No''.
Sample Input
3 2 1 2 2 4 1 1 2
Sample Output
Yes No No
Source
2017中国大学生程序设计竞赛 - 女生专场

题目描述:一种所有结点都有边与之相连的匹配叫做完美匹配。现在你有N个结点,对于n-1个结点,你有两种操作:
(1):将这个结点与之前的所有结点都连一条边
(2):不进行操作;
问你组成的这张图有没有可能是完美匹配。
题面分析:这是一道很有意思的思维题。首先要明确的一点是题目只要我们求是否可能是完美匹配,而不是让我们判断是否一定是完美匹配。对于每个结点,当我们要进行第一种操作时,即意味着我们这个结点可以与前面的任意一个结点进行匹配;而当我们进行第二种操作的时候,意味着这个结点是完全孤立的。因为每次操作1时,当前节点的匹配是任意的,考虑到这点,我们可以考虑使用队列去做,即当进行操作1的时候,队列深度减1,当操作为2时,将队列深度加1,最后判断队列是否非空即可。
而又考虑到这题中的结点对结果没有影响,故直接开一个数进行加一减一的模拟即可。
#include <bits/stdc++.h>
using namespace std;
int main()
{int t;cin>>t;while(t--){int n,num;cin>>n;if(n%2==1){for(int i=1;i<n;i++){cin>>num;}puts("No");continue;}int que=1;for(int i=1;i<n;i++){cin>>num;if((num==1&&que==0)||num==2){que++;}else que--;}if(que==0){puts("Yes");}else puts("No");}return 0;
}

转载于:https://www.cnblogs.com/Chen-Jr/p/11007311.html

HDU 6029(思维)相关推荐

  1. 2018 Spring Team Contest D HDU - 6023、HDU - 6024、HDU - 6025 、HDU - 6027 、HDU - 6029

    HDU - 6023  //编译错误不算罚时 #include<cstdio> #include<cstring> #include<iostream> #incl ...

  2. hdu 6029 Graph Theory 【直接连线】

    hdu 6029 Graph Theory [直接连线] 对于输入的a等于1  如果前面有空闲的点 直接匹配 否则自己变成空闲的点 a=2 的时候  空闲的点加一 直到最后 如果没有空余的点 输出ye ...

  3. The Fool HDU 6555 思维/数论

    开个根就行 #include <cstdio> #include <algorithm> #include <cmath> #include <cstring ...

  4. 2018 China Collegiate Programming Contest - Jilin Site F - The Hermit HDU - 6560 思维

    链接Problem - 6560 题意 有n个站点每个站点可以发送完美信号 关于完美信号的定义 有i j k三个站点 分别保证 i<j<k dis(i,j)> dis(j,k) 并且 ...

  5. SDNU-多校训练赛2-[ABF]

    问题虫洞--A:A - Just Skip The Problem HDU - 6600 黑洞内窥: 给出一个数n, 而你也将得到一个连你自己也不到的数X, 然后你可以用这个数X去和一个Y进行与运算, ...

  6. WHUT第七周训练整理

    WHUT第七周训练整理 祝各位武理的ACMer们,新年快乐!在接下来的一年里继续训练,为武理的ACM揭开新的篇章!同为武汉的学子,武汉加油! 索引 (难度由题目自身难度与本周做题情况进行分类,仅供新生 ...

  7. hdu 3234 Exclusive-OR 题解(并查集,思维)

    该死的期末复习终于结束了... 暑假来了\color{#ff0000}{暑假来了}暑假来了!!! 所以我就珂以非常开心的写博客了. 原题链接: hdu 题意简述 多组数据.你有一个没有确定的数列.有一 ...

  8. HDU - 6486 Flower(思维)

    HDU - 6486 Flower 题目大意:有n堆草每次只能对n-1堆操作每次只能减1问最少操作几次能把这些草剪到相同高度如果不能输出-1 我们让n-1个数减1实际上可以看成使得剩下的那一个数加1. ...

  9. HDU - 5637 Transform (思维、bfs预处理)

    HDU - 5637 题目大意: 给出n个数的序列a,对于一个整数x,有两种操作: 1.改变x二进制中任一位 2.将x变为x^a[i] m次查询,每次查询输入两个整数x和y,问x最少经过多少次操作可以 ...

最新文章

  1. LeetCode Minimum Path Sum(动态规划)
  2. stringstream精度问题
  3. python3小游戏源代码_如何用python3代码玩小游戏?
  4. boost::hana::zip用法的测试程序
  5. 566.重塑矩阵(力扣leetcode) 博主可答疑该问题
  6. 资产管理(记账系统)03
  7. 域格4G模组开机网络注册流程
  8. 微表情测试软件排行榜,微表情心理测试分析系统:以“微”见智,识情绪辨人心...
  9. PageHelper.startPage分页的使用和pageSize的值和list相同导致循环出来的total总数不对
  10. android opengl 帧动画,Android OpenGLES2.0(十三)——流畅的播放逐帧动画
  11. android bugly 错误分析,# app 3.6.1 Bugly中崩溃分析
  12. 微信小程序中苹果iOS手机显示时间格式NaN不正确的问题
  13. JQuery实现图片点击放大
  14. new HashMap(list.size())指定size就能完全避免扩容带来的额外开销了吗?
  15. Suzy找到实习了吗Day 14 | 二叉树开始啦 二叉树的分类、定义、遍历方法
  16. 烤仔说 | Babe Babe Běibèi oh~
  17. 铅酸蓄电池知识(待更新)
  18. 3个5相乘列乘法算式_「百树云课堂」初一数学必考的知识点(21个)
  19. 区块链阴谋与骗局 贴吧
  20. 华为imana命令行

热门文章

  1. 深度学习之卷积神经网络(6)梯度传播
  2. 原生js绑定click为什么点一次执行两次_前端小知识10点(2020.10.8)
  3. 『操作系统』 进程的描述与控制 Part2 进程同步
  4. C++获取当前系统时间并格式化输出
  5. Linux更改主机名称(hostname)和设置DNS解析以及设置IP
  6. linux下shell命令别名(alias)设置
  7. 【人脸对齐-Landmarks】300W 数据集
  8. angular 使用data-bs-datepicker时的一个小问题及解决
  9. 使用GridSearchCV和RandomizedSearchCV进行超参数调整
  10. SorterBot-第1部分