卖书

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 1000010
using namespace std;
int n,a[maxn],cnt1,cnt2;
int qread(){
int i=;
char ch=getchar();
while(ch<''||ch>'')ch=getchar();
while(ch<=''&&ch>=''){i=i*+ch-'';ch=getchar();}
return i;
}
int main(){
freopen("book.in","r",stdin);freopen("book.out","w",stdout);
// freopen("Cola.txt","r",stdin);
scanf("%d",&n);
for(int i=;i<=n;i++)a[i]=qread();
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 ;
}

100分 贪心

写代码

#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 1000010
using namespace std;
int n,a[maxn],s1[maxn],s2[maxn],top1,top2,m,sid1[maxn],sid2[maxn],b[maxn];
bool ex[maxn];
void out(){
for(int i=;i<=n;i++){
if(b[i]==)printf("+%d ",a[i]);
else printf("-%d ",a[i]);
}
}
int main(){
freopen("program.in","r",stdin);freopen("program.out","w",stdout);
// freopen("Cola.txt","r",stdin);
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);ex[x]=;}
for(int i=;i<=n;i++){
if(ex[i]){
top2+=;
s2[top2]=a[i];b[i]=-;
sid2[top2]=i;
while(top2){
if(s2[top2]==s1[top1]){
b[sid2[top2]]=-;
b[sid1[top1]]=;
top1-=;top2-=;
}
else{
sid2[top2+]=sid1[top1];
top2+=;
s2[top2]=s1[top1];top1-=;
}
if(top1<){puts("NO");return ;}
}
}
else{
top1+=;
s1[top1]=a[i];
sid1[top1]=i;
}
}
if(top1==&&top2==){
out();
return ;
}
while(top1){
s2[++top2]=s1[top1];
sid2[top2]=sid1[top1];top1--;
while(top2){
if(s2[top2]==s1[top1]){
b[sid2[top2]]=-;
b[sid1[top1]]=;
top1--;top2--;
}
else{
sid2[top2+]=sid1[top1];
s2[++top2]=s1[top1--];
}
if(top1<){puts("NO");return ;}
}
}
out();return ;
}

100分 括号匹配

迷宫

#include<iostream>
#include<cstdio>
#include<vector>
#define maxn 110
using namespace std;
int n,m,num,head[maxn],q,s,t,st[maxn],top;
struct node{
int to,pre,v;
}e[maxn*maxn*];
void Insert(int from,int to,int v){
e[++num].to=to;
e[num].v=v;
e[num].pre=head[from];
head[from]=num;
}
bool vis[maxn],flag;
void dfs(int now){
if(now==t&&top==){
flag=;
return;
}
if(flag)return;
vector<int>zu;
for(int i=;i<=top;i++)zu.push_back(st[i]);
for(int i=head[now];i;i=e[i].pre){
int to=e[i].to;
if(vis[to])continue;
else{
vis[to]=;
if(e[i].v==){
dfs(to);
top=;
for(int j=;j<zu.size();j++)st[++top]=zu[j];
vis[to]=;
continue;
}
for(int j=;j<=;j+=){
if(e[i].v>){
for(int k=;k<=j;k++){
top=top+;
st[top]=e[i].v;
}
dfs(to);
if(flag)return;
top=;
for(int k=;k<zu.size();k++)top=top+,st[top]=zu[k];
}
if(e[i].v<){
top-=j-;
if(st[top]!=-e[i].v||top<)break;
else top-=;
dfs(to);
top=;
for(int k=;k<zu.size();k++)st[++top]=zu[k];
}
}
vis[to]=;
}
}
}
int main(){
freopen("maze.in","r",stdin);freopen("maze.out","w",stdout);
// freopen("Cola.txt","r",stdin);
scanf("%d%d",&n,&m);
int x,y,z;
for(int i=;i<=m;i++){
scanf("%d%d%d",&x,&y,&z);
Insert(x,y,z);Insert(y,x,z);
}
scanf("%d",&q);
while(q--){
flag=;top=;
scanf("%d%d",&s,&t);
vis[s]=;
dfs(s);
vis[s]=;
if(flag)puts("YES");
else puts("NO");
}
return ;
}

5分 暴力

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;
int n,m,g[][][],q[**][],t,x,y,z;
int main(){
// freopen("maze.in","r",stdin);freopen("maze.out","w",stdout);
freopen("maze20.in","r",stdin);
scanf("%d%d",&n,&m);
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][],y=q[s][],sta=q[s][];
if(sta!=){
for(int i=;i<=n;i++){
if(g[i][x][sta-]==){
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][]==)puts("YES");
else puts("NO");
}
}

100分 动态规划

预计得分100++
实际得分100++
T1较简单,是以前做过的原题。T2看到函数递归就觉得应该和栈有关系,仔细研究,这不就是个括号序列吗,一开始以为要用双向链表,后来发现加个数组记录一下id,再加一个栈模拟退栈就好了,虽然和标解不太一样,但是A了。T3我思索良久,想过建分层图,但复杂度太高,正确性也很玄学,所以就写了个dfs,才搜了5分
今天的题都是关于栈的,发挥的还好,但我觉得T3的dfs应该再优化一下,尽量拿到更多部分分

小结

清北刷题冲刺 11-02 a.m的更多相关文章

  1. 清北刷题冲刺 11-03 a.m

    纸牌 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> ...

  2. 2017-10-2 清北刷题冲刺班a.m

    一道图论神题 (god) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK有一张无向图G={V,E},这张无向图有n个点m条边组成.并且这是一张带权图,只 ...

  3. 2017-10-2 清北刷题冲刺班p.m

    最大值 (max) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK有一本书,上面有很多有趣的OI问题.今天LYK看到了这么一道题目: 这里有一个长度为n ...

  4. 清北刷题冲刺 11-01 p.m

    轮换 #include<iostream> #include<cstdio> #include<cstring> #define maxn 1010 using n ...

  5. 清北刷题冲刺 10-31 a.m

    集合 #include<iostream> #include<cstdio> #include<algorithm> using namespace std; ], ...

  6. 清北刷题冲刺 10-30 a.m

    星空 #include<iostream> #include<cstdio> using namespace std; int n,m; int main(){ freopen ...

  7. 清北刷题冲刺 10-29 p.m

    洗澡 /* 这个题不能单纯判断左括号和右括号的多少,而应该从左到右扫一遍,看应该如何配对 */ #include<iostream> #include<cstdio> #inc ...

  8. 清北刷题冲刺 10-28 p.m

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

  9. 清北刷题冲刺 10-28 a.m

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

随机推荐

  1. 单机版 JedisUtil({基本操作封装工具类})【二】

    <!--集成的RedisJAR--> <!--引入jedis需的jar包--> <dependency> <groupId>redis.clients& ...

  2. Php处理大文件-分割和合并

    分割文件 /* * 分割文件 * 默认大小 2M=10485760/5 */ function file_split($file,$block_size=10485760/5) { $block_in ...

  3. linux应用之vim的常用命令

    vim 选择文本,删除,复制,粘贴 文本的选择,对于编辑器来说,是很基本的东西,也经常被用到,总结如下: v 从光标当前位置开始,光标所经过的地方会被选中,再按一下v结束. V 从光标当前行开始,光标 ...

  4. (转)java向MySQL插入当前时间的四种方式和java时间日期格式化的几种方法(案例说明)

    java向MySQL插入当前时间的四种方式和java时间日期格式化的几种方法(案例说明);部分资料参考网络资源 1. java向MySQL插入当前时间的四种方式 第一种:将java.util.Date ...

  5. js之__proto__原型链

    可参考: http://blog.csdn.net/irelandken/article/details/7297490

  6. MySQL Explain详解(转)

    explain SELECT a.* FROM test a,(select id from test where level_id <=4 order by aa_id limit 24300 ...

  7. tx2在自制载板上无法识别usb以及pcie无法读取数据

    注意使用的系统版本是Jetpack-3.1,其它版本的系统上没有测试过!!! 刷机时替换dtb文件: 将Jetpack刷机包 64_TX2/Linux_for_Tegra_tx2/kernel/dtb ...

  8. shell入门-grep过滤-1

    正则表达式,就是一个字符串.有一定的规律.我们用指定的字符串匹配一个指定的行.指定的字符串就是正则表达式. 正则表达式有这几个工具:grep egrep sed awk 命令:gerep 说明:过滤出 ...

  9. Neural Networks and Deep Learning 笔记

    1 Introduction to Deep Learning 介绍了神经网络的定义,有监督学习,分析了为什么深度学习会崛起 1.1 结构化数据/非结构化数据 结构化数据:有一个确切的数据库,有key ...

  10. SAP 销售订单中采购标识无法修改

    VA03中的销售订单第四个物料没有ZA选项, 错误提示:计划行类别ZA未定义 原因: MM03中的 MRP2---采购类型未被定义