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 - ...
随机推荐
- Redis Sentinel 介绍
Redis Sentinel sentinel的功能: 监控:sentinel节点定期检测redis数据节点,其余sentinel节点是否可达. 通知:sentinel 节点会将故障转移结果通知给 ...
- 文件后缀与Mime类型对照表
以下是一些文件后缀(扩展名)对应的MIME类型的一个对照表,方便iis中或其他服务器对相应的文件进行解析.有些文件的后缀名没有默认解析就出现上传后无法访问或者下载的问题,这个时候就要设置文件后缀对应的 ...
- xp sp3安装.Net 4.0提示严重错误,0x80070643,解决办法2017版
客户电脑上要装金税开票软件,需要.net 4.0.30319.1,电脑环境是xp sp3,已经安装了.net 2, .net 3.5sp1,安装.net 4.0的时候提示错误0x80070643 因为 ...
- yii学习笔记(3),自定义全局工具函数
在平时开发是经常需要打印数据来调试 常见的打印方式有print_r和var_dump,但是这样打印出来格式很乱不好浏览 在打印函数前后加上<pre></pre>就可以将内容原样 ...
- Hive(4)-Hive的数据类型
一. 基本数据类型 Hive数据类型 Java数据类型 长度 例子 TINYINT byte 1byte有符号整数 20 SMALINT short 2byte有符号整数 20 INT int 4by ...
- spark2.2 从入门到精通 视频教程 百度云网盘下载地址
spark2.2 从入门到精通 视频教程 百度云网盘下载地址 链接:https://pan.baidu.com/s/1sm2Jdmt 密码:rdea
- java-IO处理类的序列化与反序列化
package TestIo; import java.io.*; /** * 序列化 * * * 对象序列化 * * 一 创建对象 需要说明,想序列化的对象一定要是实现Serivalizable接口 ...
- CakePHP Model中( 获取Session)使用Component的方法
有时候我们需要在Model中使用Session,大家知道CakePHP把操作Session的方法封装为了一个Component, 在Model中正常读取Session的方法: 在 "app_ ...
- oracle 建立一个视图,然后授权其他用户访问
grant select on V_LIC_ENTRY_HZ_STATUS to ielicr2013; create or replace view dept_sum_vw (name,minsal ...
- 转 Cobar使用文档(可用作MySQL大型集群解决方案)
转自:http://blog.csdn.net/shagoo/article/details/8191346 最近好不容易抽空研究了下Cobar,感觉这个产品确实很不错(在文档方面比Amoeba强多了 ...