#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. 【04】 CSS开发注意事项

    [04] CSS注意事项 1. 页面编码规范 1.1. 统一使用 UTF-8 编码,用@charset "utf-8"指定页面编码. 1.2. 全局字体设置: windows 7系 ...

  2. xcap发包工具的简单使用3(报文描述)

    之前详细介绍了如何构造以及发送报文,现在简单对报文描述一下 1.Ethernet MAC:填写报文目的mac和源mac地址 Vlan:支持单vlan,QinQ,如果有更多的vlan,请填写在“More ...

  3. java的动态代理机制详解-----https://www.cnblogs.com/xiaoluo501395377/p/3383130.html

    java的动态代理机制详解-----https://www.cnblogs.com/xiaoluo501395377/p/3383130.html

  4. poj 3648 2-sat 输出任意一组解模板

    转载地址:http://blog.csdn.net/qq172108805/article/details/7603351 /* 2-sat问题,题意:有对情侣结婚,请来n-1对夫妇,算上他们自己共n ...

  5. SOJ 2749_The Fewest Coins

    [题意]:已知整个交易系统有N (1 ≤ N ≤ 100)种不同的货币,分别价值V1,V2,V3.......VN(1 ≤ Vi ≤ 120),FJ分别有C1,C2,C3.....CN(0 ≤ Ci ...

  6. [bzoj4994][Usaco2017 Feb]Why Did the Cow Cross the Road III_树状数组

    Why Did the Cow Cross the Road III bzoj-4994 Usaco-2017 Feb 题目大意:给定一个长度为$2n$的序列,$1$~$n$个出现过两次,$i$第一次 ...

  7. cogs——21. [HAOI2005] 希望小学

    21. [HAOI2005] 希望小学 ★★   输入文件:hopeschool.in   输出文件:hopeschool.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述 ...

  8. 07-js数组

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. mysql 经常使用命令整理总结

    #改动字段类型 alter table `table_name` modify column ip varchar(50); #添加字段 alter table `table_name` add ip ...

  10. 基于MFC的一个简单计算器

    写一个简单的计算器并不是什么很难的事,主要目的是要通过这个程序来学习和分析其中的核心算法.这个简易计算器的核心部分就是对输入的表达式的正确性判断与求值,其中包括对表达式的解析.中缀表达式转后缀表达式. ...