清北考前刷题day6早安


#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早安的更多相关文章
- 清北考前刷题day4早安
LI /* 没有考虑次大值有大于一个的情况 */ #include<iostream> #include<cstdio> #include<cstring> # ...
- 清北考前刷题day7早安
- 清北考前刷题day6下午好
/* 贪心 负数一定不取 枚举最高位是1 且答案取为0的 位置, 更新答案. */ #include<iostream> #include<cstdio> #include&l ...
- 清北考前刷题day5早安
/* C(n,k) */ #include<iostream> #include<cstdio> #include<cstring> #define ll long ...
- 清北考前刷题day2早安
/* 做法一:按h sort一遍,对于一段区间[i,j],高度花费就是h[j]-h[i] 然后枚举区间,把区间内C排序,一个一个尽量选即可. n^3logn 标算:n^3 dp 高度排序,保证从前往后 ...
- 清北考前刷题day1早安
立方数(cubic) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK定义了一个数叫“立方数”,若一个数可以被写作是一个正整数的3次方,则这个数就是立方数 ...
- 清北考前刷题day1下午好
水题(water) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK出了道水题. 这个水题是这样的:有两副牌,每副牌都有n张. 对于第一副牌的每张牌长和宽 ...
- 清北考前刷题da7下午好
三向城 /* 原图一定是一棵完全二叉树. 根节点是x,左节点是x*2,右节点是x*2+1 转化为二进制往左右走就很明显了. */ #include<iostream> #include&l ...
- 清北考前刷题da5下午好
/* (4,1)*(3,1)*(2,1)的话1变成2然后一直是2 2变成1然后变成3 3变成1然后变成4 4变成1 */ #include<iostream> #include<cs ...
随机推荐
- c# TcpClient简易聊天工具
说明: TcpClient 链接是一个比较安全稳定的链接,作为聊天或者是数据稳定传输,是比较合适的,下面的代码测试过,如果你吧他放在公网服务器上,也是可以用的 using System; using ...
- JQuery_九大选择器
JQuery_九大选择器-----https://blog.csdn.net/pseudonym_/article/details/76093261
- MYSQL Sorting result 把队列堆满了,该怎么办?
show processlist;发现有200多个队列,select cardnum from table where xxxid = 31 order by abc_time desc 这样的一个排 ...
- socketserver模块使用 & websocket
socketserver: socketserver可用于实现并发通信. socketserver 模块简化了编写网络服务程序的任务:同时 SocketServer 模块也是 Python标准库中很多 ...
- Uva - 12230 Crossing Rivers (数学期望)
你住在村庄A,每天需要过很多条河到另一个村庄B上班,B在A的右边,所有的河都在A,B之间,幸运的是每条船上都有自由移动的自动船, 因此只要到达河左岸然后等船过来,在右岸下船,上船之后船的速度不变.现在 ...
- poj_2506_Tiling_201407211555
Tiling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7509 Accepted: 3672 Descriptio ...
- 博弈论入门题 kiki's game
Problem Description Recently kiki has nothing to do. While she is bored, an idea appears in his mind ...
- Canon iP2780/iP2788 清零软件
http://www.drvsky.com/driver/iP2780_Tools.htm http://www.dyjqd.com/soft/6085.html#download http://v. ...
- python dos2unix
有时你在windows上创建的文件拿到Linux/unix上运行会出错, 这是因为windows上有些字符如换行符在linux/unix不识别.这种情况下需要用dos2unix这个工具把文件转换成li ...
- 如何使用python书写守护进程?daemon、python-daemon
可以参考的supervisor实现:https://github.com/Supervisor/supervisor:http://supervisord.org/configuration.html ...