#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm> #define N 1000010 using namespace std;
int n,a[N],cnt1,cnt2;
int read()
{
int x=,f=;char c=getchar();
while(c>''||c<''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return ;
}
int main()
{
scanf("%d",&n);
for(int i=; i<=n; i++)a[i]=read();
for(int i=; i<=n; i++)
{
if(a[i]==)cnt1++;
if(a[i]==)
{
if(cnt1==)
{
puts("NO");return ;
}
else cnt2++,cnt1--;
}
if(a[i]==)
{
if(cnt1==||(cnt2==&&cnt1<))
{
puts("NO");
return ;
}
if(cnt2) cnt2--,cnt1--;
else cnt1-=;
}
}
puts("YES");
return ;
}

/*
贪心
反过来括号匹配。
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
''
using namespace std;
const int maxn = ;
int p = ;
int z[maxn],a[maxn],n,m; int main()
{
scanf("%d",&n);
for (int i = ; i<=n; i++)
scanf("%d",&a[i]);
scanf("%d",&m);
int x;
for (int i = ; i<=m; i++)
{
scanf("%d",&x);
if (a[x]>) a[x] = -a[x];
}
for (int x = n; x>=; x--)
{
if (a[x]>)
{
if (z[p] == -a[x]) p--;
else
{
a[x] = -a[x];
p++;
z[p]= a[x];
}
}
else
{
p++;z[p]=a[x];
}
}
if (p==)
{
for (int i = ; i<=n; i++)
{
if (a[i]>) printf("+%d ",a[i]);
else printf("%d ",a[i]);
}
}
else printf("NO\n");
return ;
}

/*
Floyed
F[i][j][k]表示从i到j能否以k的方式到达。
K = 括号完全匹配 或者 缺少一个右括号
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std;
int n,m;
int g[][][],q[**][],t,x,y,z;
int main()
{
freopen("maze.in","r",stdin);
freopen("maze.out","w",stdout);
scanf("%d%d",&n,&m);
memset(g,,sizeof(g));
t = ;
for (int i = ; i<=m; i++)
{
scanf("%d%d%d",&x,&y,&z);
if (z!=)
{
if (z<) z = abs(z);
else z+=;
g[x][y][z] = ;
g[y][x][z] = ;
}
else
{
g[x][y][z] = ;
g[y][x][z] = ;
t++;
q[t][] = x;
q[t][] = y;
q[t][] = ;
t++;
q[t][] = y;
q[t][] = x;
q[t][] = ;
}
}
for (int i =; i<=n; i++)
{
g[i][i][] = ;
t++;
q[t][] = i;
q[t][] = i;
q[t][] = ;
}
for (int s = ; s<=t; s++)
{
int x = q[s][];
int y = q[s][];
int status = q[s][];
if (status!=)
{
for (int i = ; i<=n; i++)
if (g[i][x][status-] == )
{
if (g[i][y][] ==)
{
g[i][y][] = ;
t++;
q[t][] = i;
q[t][] = y;
q[t][] = ;
}
}
}
else
{
for (int i =; i<=n; i++)
{
if (g[i][x][] == && g[i][y][] == )
{
g[i][y][] =;
t++;
q[t][]= i;
q[t][] = y;
q[t][]= ;
}
if (g[y][i][] == && g[x][i][] ==)
{
g[x][i][] = ;
t++;
q[t][] = x;
q[t][] = i;
q[t][]= ;
}
for (int j = ; j<=; j ++)
{
if (g[y][i][j] == && g[x][i][j+] == )
{
g[x][i][j+] = ;
t++;
q[t][] = x;
q[t][] = i;
q[t][] = j+;
}
}
}
}
}
int tt = ;
scanf("%d",&tt);
for (; tt; tt--)
{
scanf("%d%d",&x,&y);
if (g[x][y][] ==) printf("YES\n");
else printf("NO\n");
}
}

清北考前刷题day6早安的更多相关文章

  1. 清北考前刷题day4早安

      LI /* 没有考虑次大值有大于一个的情况 */ #include<iostream> #include<cstdio> #include<cstring> # ...

  2. 清北考前刷题day7早安

  3. 清北考前刷题day6下午好

    /* 贪心 负数一定不取 枚举最高位是1 且答案取为0的 位置, 更新答案. */ #include<iostream> #include<cstdio> #include&l ...

  4. 清北考前刷题day5早安

    /* C(n,k) */ #include<iostream> #include<cstdio> #include<cstring> #define ll long ...

  5. 清北考前刷题day2早安

    /* 做法一:按h sort一遍,对于一段区间[i,j],高度花费就是h[j]-h[i] 然后枚举区间,把区间内C排序,一个一个尽量选即可. n^3logn 标算:n^3 dp 高度排序,保证从前往后 ...

  6. 清北考前刷题day1早安

    立方数(cubic) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK定义了一个数叫“立方数”,若一个数可以被写作是一个正整数的3次方,则这个数就是立方数 ...

  7. 清北考前刷题day1下午好

    水题(water) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK出了道水题. 这个水题是这样的:有两副牌,每副牌都有n张. 对于第一副牌的每张牌长和宽 ...

  8. 清北考前刷题da7下午好

    三向城 /* 原图一定是一棵完全二叉树. 根节点是x,左节点是x*2,右节点是x*2+1 转化为二进制往左右走就很明显了. */ #include<iostream> #include&l ...

  9. 清北考前刷题da5下午好

    /* (4,1)*(3,1)*(2,1)的话1变成2然后一直是2 2变成1然后变成3 3变成1然后变成4 4变成1 */ #include<iostream> #include<cs ...

随机推荐

  1. jQuery调用WCF 说明

    在项目中用过一些WCF的技术这篇文章是对以前用过的一点东西的一个梳理 一,webconfig的配置除了一般的配置外,与WCF相关的配置如下 <system.serviceModel>    ...

  2. ORACLE ASH/AWR

    (一) ASH 用户在ORACLE数据库中执行操作时,必然要创建相应的连接和会话,其中,所有当前的会话信息都保存在动态性能视图V$SESSION中,通过该视图,DBA可以查看用户实际执行的操作,或者当 ...

  3. docsearch & algolia

    docsearch & algolia The easiest way to add search to your documentation. https://community.algol ...

  4. j简单的分类实现-K近邻

          dataSetSize=dataSet.shape[0]                          voteIlabel=labels[sortedDistIndicies[i]] ...

  5. Operating system management of address-translation-related data structures and hardware lookasides

    An approach is provided in a hypervised computer system where a page table request is at an operatin ...

  6. BNU2017校赛

    A(模拟) 题意:求一个特殊图的最大流 分析:画画图发现就是for循环扫一遍 B(LCA) 题意:有n个点组成的树,有q个询问,每个询问(A,B,C),学生从B点走最短路径走到C点,再从C点走到根节点 ...

  7. Python/Java程序员面试必备常用问题解析与答案

    转自AI算法联盟,理解python技术问题,以及一些常见的java面试中经常遇到的问题,这些面试问题分为四类: 是什么(what) 如何做(how) 说区别/谈优势(difference) 实践操作( ...

  8. JSP的会话(Session)跟踪

    以下内容引用自http://wiki.jikexueyuan.com/project/jsp/session-tracking.html: 会话(Session) HTTP是一个“无状态”协议,这意味 ...

  9. CentOS系统下Hadoop、Hbase、Zookeeper安装配置

    近期给一个项目搭建linux下的大数据处理环境,系统是CentOS 6.3.主要是配置JDK.安装Tomcat,Hadoop.HBase和Zookeeper软件.博主在Hadoop这方面也是新手.配置 ...

  10. Ubuntu和Win7双系统,ubuntu被删,重新启动之后显示,no such partition

    准备一张windows7的系统安装盘.从光盘启动电脑,在光盘启动完毕之后.按shift+F10,调出cmd命令终端,在终端输入:bootrec/fixmbr OK.重新启动之后就搞定了