2017中国大学生程序设计竞赛 - 女生专场(Graph Theory)
Graph Theory
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1796 Accepted Submission(s):
750
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.
, 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
,a
3
,...,a
n
(1≤a
i
≤2)
, denoting the decision on each vertice.
If the graph has perfect matching, output ''Yes'', otherwise output
''No''.
2
1
2
2
4
1 1 2
No
No
several similar problems for you: 6286 6285 6284 6283 6282
#include <iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<deque>
#include<vector>
#define ll long long
#define inf 0x3f3f3f3f
#define mod 1000000007;
using namespace std;
int a[];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
int s1=;
int s2=;
int x;
bool f=;
for(int i=;i<=n;i++)
{//2只能靠后面的1把它连上边 scanf("%d",&x);
a[i]=x;
}
for(int i=n;i>=;i--)//倒着遍历,从后往前看的话,1的数量一定要比2多
{
if(a[i]==) s1++;
else s2++;
if(s2>s1)
{
f=;
break;
}
}
if(n%==||!f||x!=) printf("No\n");//奇数个点肯定不行
else printf("Yes\n");
}
return ;
}
2017中国大学生程序设计竞赛 - 女生专场(Graph Theory)的更多相关文章
- 2017中国大学生程序设计竞赛 - 女生专场 Deleting Edges(思维+最短路)
Deleting Edges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 2017中国大学生程序设计竞赛 - 女生专场 Happy Necklace(递推+矩阵快速幂)
Happy Necklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 2017中国大学生程序设计竞赛 - 女生专场(dp)
Building Shops Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) To ...
- 2017中国大学生程序设计竞赛 - 女生专场 1002 dp
Building Shops Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 2017中国大学生程序设计竞赛 - 女生专场C【前后缀GCD】
C HDU - 6025 [题意]:去除数列中的一个数字,使去除后的数列中所有数字的gcd尽可能大. [分析]: 数组prefixgcd[],对于prefixgcd[i]=g,g为a[0]-a[i]的 ...
- 2017中国大学生程序设计竞赛 - 女生专场B【DP】
B HDU - 6024 [题意]:n个教室,选一些教室建造糖果商店. 每个教室,有一个坐标xi和在这个教室建造糖果商店的花费ci. 对于每一个教室,如果这个教室建造糖果商店,花费就是ci,否则就是与 ...
- 2017中国大学生程序设计竞赛 - 女生专场A【模拟】
A HDU - 6023 [题意]:求AC题数和总时长. [分析]:模拟.设置标记数组记录AC与否,再设置错题数组记录错的次数.罚时罚在该题上,该题没AC则不计入总时间,AC则计入.已经AC的题不用再 ...
- HDU 6024(中国大学生程序设计竞赛女生专场1002)
这是CCPC女生专场的一道dp题.大佬们都说它简单,我并没有感到它有多简单. 先说一下题意:在一条直线上,有n个教室,现在我要在这些教室里从左到右地建设一些作为糖果屋,每个教室都有自己的坐标xi 和建 ...
- "巴卡斯杯" 中国大学生程序设计竞赛 - 女生专场
Combine String #include<cstdio> #include<cstring> #include<iostream> #include<a ...
随机推荐
- 读jQuery之六(缓存数据)
很多同学在项目中都喜欢将数据存储在HTMLElement属性上,如 1 2 3 4 <div data="some data">Test</div> < ...
- spring3:对JDBC的支持 之 JDBC模板类
7.2 JDBC模板类 7.2.1 概述 Spring JDBC抽象框架core包提供了JDBC模板类,其中JdbcTemplate是core包的核心类,所以其他模板类都是基于它封装完成的,JDB ...
- GO学习笔记:函数作为值、类型
在Go中函数也是一种变量,我们可以通过type来定义它,它的类型就是所有拥有相同的参数,相同的返回值的一种类型: type typeName func(input1 inputType1 , inpu ...
- Android进阶常用网站
Android进阶常用网站 android中文网 Android Studio 安卓开发者社区
- IOS-视频
一.简介 iOS提供了MPMoviePlayerController.MPMoviePlayerViewController两个类,可以用来轻松播放视频和网络流媒体\网络音频 提示:网络音频同样使用此 ...
- Oracle Package
(转自:http://blog.csdn.net/bbliutao/article/details/9016947) 一.概述包可将一些有联系的对象放在其内部.任何能在块定义部分出现的对象都可以在包中 ...
- Java8_02_lambda表达式
一.前言 这一节我们来了解下lambda表达式,主要关注以下几点: 行为参数化 匿名类 Lambda 表达式 方法 引用 二.行为参数化 1.概念 行为参数化(behavior parameteriz ...
- LeetCode OJ:Three Sum(三数之和)
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all un ...
- Java.lang包的接口解读
Java.lang包中提供了八个接口: 1.Appendable 能够被追加 char 序列和值的对象.如果某个类的实例打算接收来自 Formatter的格式化输出,那么该类必须实现 Appendab ...
- ubuntu android 开始git安装
ubuntu android 开始git安装 git安装: http://source.android.com/source/initializing.html网站提示到以下网址下载: http: ...