HDU6029 Graph Theory 2017-05-07 19:04 40人阅读 评论(0) 收藏
Graph Theory
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072
K (Java/Others)
Total Submission(s): 17 Accepted Submission(s): 10
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,a3,...,an(1≤ai≤2),
denoting the decision on each vertice.
3
2
1
2
2
4
1 1 2
Yes
No
No
题意:有n个点,每个点有两种连边方式,1表示和前面所有的点连边,2表示和前面所有的点不连边,问能不能构成完美匹配
解题思路:若n为奇数,则不可能;n为偶数时,从后向前判,看方式1的个数是否一直大于方式2
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <functional> using namespace std; #define LL long long
const int INF=0x3f3f3f3f; int a[100005]; int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=1; i<n; i++)
scanf("%d",&a[i]);
if(n%2)
{
printf("No\n");
}
else
{
int cnt=0;
int flag=0;
for(int i=n-1; i>=1; i--)
{
if(a[i]==1)
cnt++;
else
{
if(cnt==0)
{
flag=1;
break;
}
cnt--;
}
}
if(flag) printf("No\n");
else printf("Yes\n");
}
}
return 0;
}
HDU6029 Graph Theory 2017-05-07 19:04 40人阅读 评论(0) 收藏的更多相关文章
- HDU6026 Deleting Edges 2017-05-07 19:30 38人阅读 评论(0) 收藏
Deleting Edges Time ...
- cubieboard变身AP 分类: ubuntu cubieboard 2014-11-25 14:04 277人阅读 评论(0) 收藏
加载bcmdhd模块:# modprobe bcmdhd 如果你希望开启 AP 模式,那么:# modprobe bcmdhd op_mode=2 在/etc/modules文件内添加bcmdhd o ...
- HDU6029 Happy Necklace 2017-05-07 19:11 45人阅读 评论(0) 收藏
Happy Necklace Time Limit: ...
- 滑雪 分类: POJ 2015-07-23 19:48 9人阅读 评论(0) 收藏
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 83276 Accepted: 31159 Description Mich ...
- iOS开发之监听键盘高度的变化 分类: ios技术 2015-04-21 12:04 233人阅读 评论(0) 收藏
最近做的项目中,有一个类似微博中的评论转发功能,屏幕底端有一个输入框用textView来做,当textView成为第一响应者的时候它的Y值随着键盘高度的改变而改变,保证textView紧贴着键盘,但又 ...
- POJ3320 Jessica's Reading Problem 2017-05-25 19:55 38人阅读 评论(0) 收藏
Jessica's Reading Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12346 Accep ...
- HDU6027 Easy Summation 2017-05-07 19:02 23人阅读 评论(0) 收藏
Easy Summation Time Limit: 2000/1000 MS ...
- POJ1269 Intersecting Lines 2017-04-16 19:43 50人阅读 评论(0) 收藏
Intersecting Lines Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 15478 Accepted: 67 ...
- Making the Newsfeed web part available outside of My Sites in SharePoint 2013 分类: Sharepoint 2015-07-07 19:29 4人阅读 评论(0) 收藏
The Newsfeed is a key piece in SP2013's approach to social computing. It appears on the landing page ...
随机推荐
- 有3D效果的进度条
// The Unofficial Newsletter of Delphi Users - Issue #12 - February 23rd, 1996 unit Percnt3d; (* TPe ...
- 迭代删除元素 并发bug 低级错误
方法一:HashMap<String, Integer> myHashMap = new HashMap<>();myHashMap.put("1", 1) ...
- ValueError: update only works with $ operators
问题:在执行pymongo的update语句时,提示了ValueError: update only works with $ operators 脚本:db.user.update_one({&qu ...
- cdoj841-休生伤杜景死惊开 (逆序数变形)【线段树 树状数组】
http://acm.uestc.edu.cn/#/problem/show/841 休生伤杜景死惊开 Time Limit: 3000/1000MS (Java/Others) Memory ...
- 6.ZigZag Conversion(Graph, traverse)
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...
- dede 复制文章,远程图片无法本地化
解决方法: 1.找到dede的后台目录,在后台目录下的inc下找到inc_archives_functions.php 2.搜索GetCurContent函数,找到如下这段代码: preg_match ...
- mvc view获取url参数
视图页面直接获取url get传值, 1.@Request.QueryString["look"] 2.@ViewContext.RequestContext.HttpContex ...
- Linux tcpdump命令
一.简介 用简单的话来定义tcpdump,就是:dump the traffic on a network,根据使用者的定义对网络上的数据包进行截获的包分析工具. tcpdump可以将网络中传送的数据 ...
- Windows10电脑安装macOS Mojave系统的方法(最新版系统,含超详细步骤截图)
一.环境及准备工作 1.主机系统:本人系统是Windows10家庭中文版 2.虚拟机软件:VMware Workstation 14 Pro 虚拟机版本号:14.1.1 build-7528167 虚 ...
- 开发中常遇到的Python陷阱和注意点-乾颐堂
最近使用Python的过程中遇到了一些坑,例如用datetime.datetime.now()这个可变对象作为函数的默认参数,模块循环依赖等等. 在此记录一下,方便以后查询和补充. 避免可变对象作为默 ...