Graph Theory
Description
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
In each test case, there is an integer $n(2\leq n\leq 100000)$ in the first line, denoting the number of vertices of the graph.
The following line contains $n-1$ integers $a_2,a_3,...,a_n(1\leq a_i\leq 2)$, denoting the decision on each vertice.
Output
Sample Input
Sample Output
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
int t,n,i,count;
int a[];
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
count=;
for(i=; i<n; i++)
{
scanf("%d",&a[i]);
}
if(n%==)
{
printf("No\n");///奇数不可能配对
}
else
{
for(i=; i<n; i++)
{
if(a[i]==)
{
if(count==)
{
count=;
}
else
{
count--;
}
}
else
{
count++;
}
}
if(count==)
{
printf("Yes\n");
}
else
{
printf("No\n");
}
}
}
return ;
}
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
int t,n,i,j,a,count;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
count=;
for(i=; i<n; i++)
{
scanf("%d",&a);
if(a==||count==)
{
count++;
}
else
{
count--;
}
}
if(count==)
{
printf("Yes\n");
}
else
{
printf("No\n");
} }
return ;
}
Graph Theory的更多相关文章
- Introduction to graph theory 图论/脑网络基础
Source: Connected Brain Figure above: Bullmore E, Sporns O. Complex brain networks: graph theoretica ...
- The Beginning of the Graph Theory
The Beginning of the Graph Theory 是的,这不是一道题.最近数论刷的实在是太多了,我要开始我的图论与树的假期生活了. 祝愿我吧??!ShuraK...... poj18 ...
- Codeforces 1109D Sasha and Interesting Fact from Graph Theory (看题解) 组合数学
Sasha and Interesting Fact from Graph Theory n 个 点形成 m 个有标号森林的方案数为 F(n, m) = m * n ^ {n - 1 - m} 然后就 ...
- CF1109D Sasha and Interesting Fact from Graph Theory
CF1109D Sasha and Interesting Fact from Graph Theory 这个 \(D\) 题比赛切掉的人基本上是 \(C\) 题的 \(5,6\) 倍...果然数学计 ...
- HDU6029 Graph Theory 2017-05-07 19:04 40人阅读 评论(0) 收藏
Graph Theory Time Limit: 2000/1000 M ...
- Codeforces 1109D. Sasha and Interesting Fact from Graph Theory
Codeforces 1109D. Sasha and Interesting Fact from Graph Theory 解题思路: 这题我根本不会做,是周指导带飞我. 首先对于当前已经有 \(m ...
- 2018 Multi-University Training Contest 4 Problem L. Graph Theory Homework 【YY】
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6343 Problem L. Graph Theory Homework Time Limit: 2000 ...
- 2017中国大学生程序设计竞赛 - 女生专场(Graph Theory)
Graph Theory Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)To ...
- HDU 6343.Problem L. Graph Theory Homework-数学 (2018 Multi-University Training Contest 4 1012)
6343.Problem L. Graph Theory Homework 官方题解: 一篇写的很好的博客: HDU 6343 - Problem L. Graph Theory Homework - ...
随机推荐
- 第四模块MySQL50题作业,以及由作业引申出来的一些高端玩法
一.表关系 先参照如下表结构创建7张表格,并创建相关约束 班级表:class 学生表:student cid caption grade_id ...
- Vmware文件类型
### vmx ###> 虚拟机启动的配置文件+ 包含`.encoding`.`displayName`.`memsize`等基本配置信息,还包括一些链接文件的位置如`nvram`(非易变RAM ...
- 日常工作之Zabbix源码编译,兼容mysql5.6
原文链接:http://www.leleblog.top/daily/more?id=6 Zabbix源码编译 环境: centOS7.mysql5.6.21(已存在). 任务简述: 服务器搭建zab ...
- layui sleect获取value值
<div class="layui-form-item"> <label for="username" class="layui-f ...
- 使用PHPExcel 对表格进行,读取和写入的操作。。。。
下面的代码是使用PHPExcel 对多个表格数据进行读取, 然后整合的写入新的表格的方法!!!代码有点粗糙 , 多多保函!!! 这里有些地方注意下,如果你的表格数据过大, 一定要记得修改php.ini ...
- windows 10 安装node.js
第一步:下载软件 nodejs的中文官网http://nodejs.cn/download/ 选择 windows 系统 msi 安装版本. 下载完成之后,直接打开下一步安装就可以. 安装完成 打开 ...
- 视频网站数据MapReduce清洗及Hive数据分析
一.需求描述 利用MapReduce清洗视频网站的原数据,用Hive统计出各种TopN常规指标: 视频观看数 Top10 视频类别热度 Top10 视频观看数 Top20 所属类别包含这 Top20 ...
- Linux的数据传输
1. sz 与 rz sz:将选定的文件从本地发送(send)到远端机器 rz:运行该命令会弹出一个文件选择窗口,从本地选择文件夹,接收(receive)从远端的文件 mac 下使用 brew 安装: ...
- Redis系列化方式有哪些?哪个系列化性能最好?
Redis系列化方式有JDK系列化.JSON系列化.XML系列化等多种.我专门测试过,在我的笔记本电脑上保存5万条User对象到Redis,JDK系列化方式平均要15秒,JSON系列化方式只要13秒多 ...
- break和continue使用
前面讲的循环,这里就是控制循环的东西 break其实在我们学习switch判断的时候就是用到了 break:代表跳出整个循环 continue和break的用法差不多 continue:代表只跳出当前 ...