HDU 6029 Graph Theory【水题】

HDU图论题目分类 立即下载

Graph Theory

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


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

问题:

有n个点,1表示当前点与之前所有点连一条边,2表示不动,问通过选出其中的某些边,能否使所有的点都能够有一个点与其配对。

思路:
用cnt表示前面有多少个未配对的点,
如果前面有未配对的点则,若操作为1,,则cnt--,若操作为2则cnt++
如果前面所有的点都匹对成功则,若操作为1,,则cnt=1(因为前面没有点与其配对),若操作为2则cnt++

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<bitset>
#include<numeric>
#include<vector>
#include<string>
#include<iterator>
#include<cstring>
#include<ctime>
#include<functional>
#define INF 0x3f3f3f3f
#define ms(a,b) memset(a,b,sizeof(a))
#define pi 3.14159265358979
#define mod 1000000007
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;

typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 100010;

int n, a[maxn];

int main()
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		int cnt = 1;
		scanf("%d", &n);
		for (int i = 2; i <= n; i++)
		{
			scanf("%d", a + i);
		}
		if (n % 2 != 0) puts("No");
		else
		{
			for (int i = 2; i <= n; i++)
			{
				if (a[i] == 1)
				{
					if (cnt == 0) cnt = 1;
					else cnt--;
				}
				else cnt++;
			}
			if (cnt > 0) puts("No");
			else puts("Yes");
		}
	}
}



手把手教你用Gazebo和VINS-MONO搞定VIO SLAM仿真(附Realsense D435i模型配置) 本文详细介绍了如何使用Gazebo和VINS-MONO构建VIO SLAM仿真环境,包括Realsense D435i模型的配置与集成。通过实战指南,帮助开发者快速搭建高保真仿真平台,优化VIO性能,并解决常见问题,适用于机器人感知与定位导航领域。 阅读详情

相关推荐

TDDFT计算软件Octopus学习笔记(二):基态计算(Si)

本文以硅为例,来进行基态计算。

陈啸的博客 7315

【思维】hdu 6029 Graph Theory

Graph Theory Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 2353Accepted Submission(s): 9...

iroy33的博客 266

【收藏向】模拟电子技术超强知识点总结 20小时不挂科

模电真的有难度的一门课,一定要好好学… 用的教材是华科康华光版,其他版本教材也可参考,内容是差不多的。 话不多说直接上思维导图干货(后有思维导图高清原图链接) 1 绪论 2 运算放大器 3 二极管及其基本电路 4 场效应管及其放大电路 5 双极结型三极管及其放大电路 三种组态总结看不清,给个特写 发现虽然csdn上传的是原图,但是显示的图片不是特别清晰,在此贴出B站知乎地址,第五章之后的内容都在上面,还可以查看原图 ———————————————————— B站专栏地址(可以点击查看原图) htt

工科狗Niko的博客 1万+

HDU6029-Graph Theory-图论简单推理

//传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6029 #include #include #include #include #include #include using namespace std; #define LL long long #define N 100005 #define M 2005 #define INF 0

survivorone的博客 1177

双目视觉实战:用Bouguet算法实现极线校正的完整代码解析

本文详细解析了Bouguet算法在双目视觉极线校正中的完整实现流程与性能调优技巧。通过旋转平分策略和基线对齐,Bouguet方法显著降低图像畸变并提升匹配精度,相比传统Hartley校正法平均重投影误差降低53%。文章涵盖从相机标定到OpenCV实战的全过程,并分享工业级调参策略,帮助开发者实现高精度立体视觉系统。

f9g0h的博客 276

从空调温控到信号降噪:一阶RC低通滤波器在Arduino和STM32上的C语言实现指南

本文详细介绍了如何在Arduino和STM32平台上使用C语言实现一阶RC低通滤波器,涵盖从基础理论到实际应用的完整流程。通过具体代码示例和优化技巧,帮助开发者有效处理传感器噪声、信号平滑等问题,提升嵌入式系统的信号处理能力。

weixin_30565199的博客 505

【HDU6029】Graph Theory(贪心+队列)

题目链接题目大意: T组数据,n个点。 对于编号为2~n的每个点,有两种选择: 1.这个点与之前的所有点连条边。 2.什么边都不连 问给你的这个图是否存在完美匹配。用队列维护没有被匹配的点 初始只有编号为1的点。 接下来对于每个点 如果选择第2个操作,说明这个点不能主动去匹配,只能被动由其他点来匹配,所以放入队列。 如果选择第一个操作,说明可以去匹配,就将队

No Program No Life 483

基于STM32开发的智能语音控制系统

本文将介绍如何使用STM32微控制器开发一个智能语音控制系统,通过语音识别模块、OLED显示屏、Wi-Fi模块等实现对家用电器或其他设备的语音控制。智能语音控制系统的核心是STM32微控制器,通过语音识别模块识别用户的语音指令,并根据指令控制家用电器或其他设备。:定期测试语音识别模块、继电器控制模块、OLED显示屏和Wi-Fi模块的工作状态,确保系统能够在各种情况下正常运行,并保持智能语音控制系统的可靠性。本系统同样适用于办公环境,可以通过语音指令控制办公室设备,如照明、空调等,提供智能化的办公体验。

stm32d1219的博客 6920

HDU 6029 Graph Theory

Graph Theory Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 37    Accepted Submission(s): 24 Problem Description Little Q loves play

DT_Zhangshuo的博客 1153

Xilinx FPGA平台GTX简易使用教程(汇总篇)

Xilinx平台GTX简易使用教程,先“知其然”,慢慢再研究“所以然”。

数字IC/FPGA杂货铺,找一找,或许有你想要的~ 3万+

WOFOST作物模型(1):PCSE环境配置

get_summary_output() 方法通常用于在 PCSE 模拟过程结束后,获取模拟结果的摘要信息,例如模拟期间的总产量、总水分需求等。它可以提供对模拟结果的快速总结,方便用户进行后续的分析和处理。用.get_output来获取过程参数,并将这些参数转为dataframe显示。用run_till_terminate()代表终止。安装好之后,打开jupyter notebook。也可以指定运行时间,并获取最后一天的参数。首先还是打开之前建好的gee虚拟环境。

所有专家都曾始于新手 683

Graph Theory HDU - 6029 留着练英语

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 th...

baku6967的博客 211

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Graph Theory HDU - 6029

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

ML-M的博客 470

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

hdu 6029 Graph Theory 思维

题目:http://acm.hdu.edu.cn/showproblem.php?pid=6029题意:有n个点,有下面两种操作 从当前点向前面所有点连一条边 从当前点不向任何点连边 问构成的图是不是一个二分图思路:奇数肯定不能构成二分图,偶数的话,我们依次判断,记录没有配对的点数,当操作1时,查看是否有没有配对的点,有的话,把当前点和某个未配对的点配对,那么未配对点数减1,没有的话,当前点就是一个

弱智就要多努力 845

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

(HDU 6029 女生专场)Graph Theory 思维题

Graph Theory Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 346 Accepted Submission(s): 167Problem Description Little Q loves playing w

STILLxjy 905

hdu 6029 Graph Theory

题目链接:hdu 6029 Graph Theory 题意: 有n个点,每个点按标号排序,现在每个点有两种操作,1表示将这个点和之前全部的点连一条边,2表示没有操作。 现在问你是否有一个边集能构成完美匹配。 完美匹配的定义为:1.每个点有且只有一条边。2.每条边的两端都没有重叠的点。 题解: 首先n为奇数的时候肯定是不行的,然后对于n为偶数的时候for一遍,看看有哪些点没有被匹配到。 ...

weixin_30634661的博客 100

hdu6029 Graph Theory (2017女生赛)

Graph Theory Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 167    Accepted Submission(s): 84 Problem Description Little Q loves playi

Hi_jiaxinwei的博客 1553

hdu 6029 Graph Theory(贪心)

Graph Theory Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 758    Accepted Submission(s): 363 Problem Description Little Q love

MR CODER 399

hdu6029 Graph Theory

思维题;如果前面有2,那么我们当前1必须和前面那个2匹配。如果前面没有2了,那么我们这个1就当做2看,因为它没法和前面的链了,它属于被连的那个#include&lt;stdio.h&gt;#include&lt;string.h&gt;#include&lt;iostream&gt;#include&lt;algorithm&gt;using namespace std;int main(){  ...

Little_boy_z的博客 300

HDU6029 Graph Theory

Graph Theory Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 477    Accepted Submission(s): 229 Problem Description Little Q love

zhj_fly的博客 568
上一篇: HDU 6027 Easy Summation【简单相加||快速幂】
下一篇: HDU 6030 Happy Necklace【矩阵快速幂】
Archger
博客等级 码龄10年 79粉丝 137原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值