#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");
}
}

最新文章

  1. 《挑战程序设计竞赛》 4.1.1 矩阵 P286
  2. Linux配置静态IP
  3. jQuery父级以及同级元素查找介绍
  4. maven:安装m2eclipse插件
  5. webpack和webpack-dev-server的区别
  6. tensorflow学习笔记2:c++程序静态链接tensorflow库加载模型文件
  7. 深入理解Major GC, Full GC, CMS
  8. 使用dd备份和恢复ASM中的数据文件头
  9. Linux 小知识翻译 - 「别名」
  10. tcpdump -i eth0 -n -vvv src or dst port 443
  11. centos 打包报错Can&#39;t connect to X11 window server using &#39;:0.0&#39; as the value of the DISPLAY variable.
  12. 【Excel】SUMIF的错位问题
  13. [SoapUI]怎样运用Schema通过*.xsd文件来验证response对应的xml文件
  14. linux shell scripts:Syntax error: Bad for loop variable
  15. UVa 11149 矩阵的幂(矩阵倍增法模板题)
  16. Yii2之发送电子邮件
  17. .apache.commons.io 源代码学习(二)FilenameUtils类
  18. iOS资讯详情页实现—WebView和TableView混合使用(转)
  19. UI:SQL语句
  20. 人脸识别(初学篇)-VS2015+opencv3.2的配置

热门文章

  1. 第一个web项目
  2. Android : reletive layout
  3. Java AOP
  4. [网络流24题] 方格取数问题(cogs 734)
  5. 建造高塔(codevs 1689)
  6. 2018/2/16 解析Logback的AppenderBase源码,并举一反三的实现Logback扩展功能的思路,以及它的实际业务应用场景
  7. Linux下汇编语言学习笔记64 ---
  8. PostgreSQL及PostGIS使用
  9. 保持WCF服务端与客户端的长连接
  10. CentOS6 设置AliNetflow 环境