LG1410 子序列 二分图判定
问题描述
题解
如果\(i<j,a_j \le a_i\),那么他它们不能在一个上升序列中。
于是在\(i,j\)之间建边,看建出来的图是不是二分图即可。
\(\mathrm{Code}\)
#include<bits/stdc++.h>
using namespace std;
template <typename Tp>
void read(Tp &x){
x=0;char ch=1;int fh;
while(ch!='-'&&(ch>'9'||ch<'0')) ch=getchar();
if(ch=='-') ch=getchar(),fh=-1;
else fh=1;
while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
x*=fh;
}
const int maxn=2007;
int n,a[maxn];
int Head[maxn],to[maxn*maxn],tot=1,Next[maxn*maxn];
void add(int x,int y){
to[++tot]=y,Next[tot]=Head[x],Head[x]=tot;
}
int col[maxn];
bool flag;
void dfs(int x,int cl){
col[x]=cl;
for(int i=Head[x];i;i=Next[i]){
int y=to[i];
if(col[y]){
if(col[y]!=3-cl){
flag=1;return;
}
continue;
}
dfs(y,3-cl);
}
}
int main(){
while((~scanf("%d",&n))&&n){
for(int i=1;i<=n;i++) read(a[i]);memset(Head,0,sizeof(Head));
memset(Next,0,sizeof(Next));tot=0;memset(col,0,sizeof(col));
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
if(a[j]<=a[i]){
add(i,j);add(j,i);
}
}
}
flag=0;
for(int i=1;i<=n;i++){
if(!col[i]) dfs(i,1);
if(flag) break;
}
if(!flag) puts("Yes!");
else puts("No!");
}
return 0;
}
LG1410 子序列 二分图判定的更多相关文章
- CF687A. NP-Hard Problem[二分图判定]
A. NP-Hard Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- COJ 0578 4019二分图判定
4019二分图判定 难度级别: B: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 给定一个具有n个顶点(顶点编号为0,1,… ...
- hdoj 3478 Catch(二分图判定+并查集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3478 思路分析:该问题需要求是否存在某一个时刻,thief可能存在图中没一个点:将该问题转换为图论问题 ...
- UVA 11080 - Place the Guards(二分图判定)
UVA 11080 - Place the Guards 题目链接 题意:一些城市.之间有道路相连,如今要安放警卫,警卫能看守到当前点周围的边,一条边仅仅能有一个警卫看守,问是否有方案,假设有最少放几 ...
- poj2942 Knights of the Round Table,无向图点双联通,二分图判定
点击打开链接 无向图点双联通.二分图判定 <span style="font-size:18px;">#include <cstdio> #include ...
- HDU2444(KB10-B 二分图判定+最大匹配)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- DFS的运用(二分图判定、无向图的割顶和桥,双连通分量,有向图的强连通分量)
一.dfs框架: vector<int>G[maxn]; //存图 int vis[maxn]; //节点访问标记 void dfs(int u) { vis[u] = ; PREVISI ...
- UVa 11396 爪分解(二分图判定)
https://vjudge.net/problem/UVA-11396 题意: 给出n个结点的简单无向图,每个点的度数均为3.你的任务是判断能否把它分解成若干爪.每条边必须属于一个爪,但同一个点可以 ...
- HihoCoder 1121 二分图一•二分图判定
二分图一•二分图判定 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 大家好,我是小Hi和小Ho的小伙伴Nettle,从这个星期开始由我来完成我们的Weekly. 新年回 ...
随机推荐
- 题解 P3693 【琪露诺的冰雪小屋】
知识点: 模拟 , 信仰 原题面 大 型 车 万 众 自 裁 现 场 分析题意: 操作: ICE_BARRAGE R C D S R:行 , C:列, D:方向 , S:强度 在(R,C) 向 D 射 ...
- Paper | Fast image processing with fully-convolutional networks
目录 故事 方法 实验 发表在2017年ICCV. 核心任务:加速图像处理算子(accelerate image processing operators). 核心方法:将算子处理前.后的图像,训练一 ...
- springboot2+shiro+jwt整合
参考:https://www.jianshu.com/p/ef0a82d471d2 https://www.jianshu.com/p/3c51832f1051 https://blog.csdn.n ...
- 一个比 AutoMapper 更快的模型映射的组件 Mapster
下面是官方的性能测试 Demo,感性的也可以去 Github 上下载. 贴出代码目的是如果后期直接从自己的博客中在线看. using System; using System.Collections. ...
- python 统计使用技巧
python 统计使用技巧 # 1.不输入回车获取值 注:需要tty模块配合. fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) ...
- LeetCode 1291. Sequential Digits
题目 class Solution { public: int ans[10005]; vector<int> sequentialDigits(int low, int high) { ...
- DVWA-文件包含学习笔记
DVWA-文件包含学习笔记 一.文件包含与漏洞 文件包含: 开发人员将相同的函数写入单独的文件中,需要使用某个函数时直接调用此文件,无需再次编写,这种文件调用的过程称文件包含. 文件包含漏洞: 开发人 ...
- 2019-3-20-UWP-How-to-custom-RichTextBlock-right-click-menu
原文:2019-3-20-UWP-How-to-custom-RichTextBlock-right-click-menu title author date CreateTime categorie ...
- Enum.GetValues(),返回System.Array的一个实例
Array enumData = Enum.GetValues(e.GetType()); Console.WriteLine("This enum has {0} members.&quo ...
- 练手WPF(四)——贪吃蛇小游戏的简易实现(下)
八.生成新的单节蛇身我们这里先说说游戏小原理好了,游戏运行后,通过计时器事件不断生成新的单节蛇身类SnakeNode,添加到List中的0位置,原来的蛇头变成了第二节.该节新蛇头的坐标通过蛇头前进方向 ...