这次的题目是著名的模拟(水逼)专题

  题目难度都不大,思维也不深,就是一个字——烦

  同时很多题目都有很多坑点

  1608 题意是告诉你一个只有()的字符串(且匹配正确),每个)的左边有几个(,让你求每一对括号中包含了几对括号。

  思路很水,模拟出原字符串再开个栈做一次就行了。

  CODE

#include<cstdio>
using namespace std;
const int N=;
int t,n,s[N],stack[N],i,j,x,last,del,top;
inline void read(int &x)
{
x=; char ch=getchar();
while (ch<''||ch>'') ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
}
inline void work(int b,int e)
{
int l=,r=;
for (int i=b;i<=e;++i)
if (!s[i]) l++; else r++;
printf("%d ",l<r?l:r);
}
int main()
{
read(t);
while (t--)
{
read(n); last=; del=;
for (i=;i<=n;++i)
{
read(x);
for (j=last;j<last+x-del;++j)
s[j]=;
s[last+x-del]=; last=last+x-del+; del=x;
}
for (i=;i<=*n;++i)
if (!s[i]) stack[++top]=i; else work(stack[top--],i);
putchar('\n');
}
return ;
}

  2632 就是一堆机器人行走让你求它们会不会撞到或者撞墙。模拟整个过程即可(毫无算法可言)

  CODE

#include<cstdio>
using namespace std;
const int N=;
struct robot
{
int x,y;
char side;
}r[N];
struct place
{
bool b;
int num;
}f[N][N];
int t,a,b,m,n,i,j,x,num,res;
char ch;
bool flag;
inline void read(int &x)
{
x=; char ch=getchar();
while (ch<''||ch>'') ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
}
inline void turn_left(int num,int step)
{
if (r[num].side=='N') res=;
if (r[num].side=='W') res=;
if (r[num].side=='S') res=;
if (r[num].side=='E') res=;
res=(res+step)%;
if (res==) r[num].side='N';
if (res==) r[num].side='W';
if (res==) r[num].side='S';
if (res==) r[num].side='E';
}
inline void turn_right(int num,int step)
{
if (r[num].side=='N') res=;
if (r[num].side=='E') res=;
if (r[num].side=='S') res=;
if (r[num].side=='W') res=;
res=(res+step)%;
if (res==) r[num].side='N';
if (res==) r[num].side='E';
if (res==) r[num].side='S';
if (res==) r[num].side='W';
}
inline void forward(int num,int step)
{
if (!step) return;
f[r[num].x][r[num].y].b=f[r[num].x][r[num].y].num=;
if (r[num].side=='N')
{
while (step--)
{
if (f[r[num].x][++r[num].y].b) { printf("Robot %d crashes into robot %d\n",num,f[r[num].x][r[num].y].num); flag=; return; }
if (r[num].y>b) { printf("Robot %d crashes into the wall\n",num); flag=; return; }
}
}
if (r[num].side=='E')
{
while (step--)
{
if (f[++r[num].x][r[num].y].b) { printf("Robot %d crashes into robot %d\n",num,f[r[num].x][r[num].y].num); flag=; return; }
if (r[num].x>a) { printf("Robot %d crashes into the wall\n",num); flag=; return; }
}
}
if (r[num].side=='S')
{
while (step--)
{
if (f[r[num].x][--r[num].y].b) { printf("Robot %d crashes into robot %d\n",num,f[r[num].x][r[num].y].num); flag=; return; }
if (!r[num].y) { printf("Robot %d crashes into the wall\n",num); flag=; return; }
}
}
if (r[num].side=='W')
{
while (step--)
{
if (f[--r[num].x][r[num].y].b) { printf("Robot %d crashes into robot %d\n",num,f[r[num].x][r[num].y].num); flag=; return; }
if (!r[num].x) { printf("Robot %d crashes into the wall\n",num); flag=; return; }
}
}
f[r[num].x][r[num].y].b=; f[r[num].x][r[num].y].num=num;
}
int main()
{
read(t);
while (t--)
{
for (i=;i<N;++i)
for (j=;j<N;++j)
f[i][j].b=f[i][j].num=; flag=;
read(a); read(b);
read(n); read(m);
for (i=;i<=n;++i)
read(r[i].x),read(r[i].y),r[i].side=getchar(),f[r[i].x][r[i].y].b=,f[r[i].x][r[i].y].num=i;
while (m--)
{
read(num); ch=getchar(); read(x);
if (flag) continue;
if (ch=='L') turn_left(num,x);
if (ch=='R') turn_right(num,x);
if (ch=='F') forward(num,x);
}
if (!flag) puts("OK");
}
return ;
}

  1573 同上,一个机器人在地图上走。让你求要走多久才能走出去或是在循环的圈长。

  DFS或模拟都可以,难度也不大

  CODE

#include<cstdio>
#include<cstring>
using namespace std;
const int N=;
char a[N][N];
int f[N][N],n,m,x,y,i,j;
inline void read(int &x)
{
x=; char ch=getchar();
while (ch<''||ch>'') ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
}
int main()
{
for (;;)
{
read(n); read(m); read(y); x=;
if (n+m+y==) break;
memset(f,,sizeof(f));
for (i=;i<=n;++i)
{
for (j=;j<=m;++j)
a[i][j]=getchar();
getchar();
}
f[x][y]=;
for (;;)
{
if (a[x][y]=='N') { if (x==) { printf("%d step(s) to exit\n",f[x][y]); break; } if (!f[x-][y]) f[x-][y]=f[x][y]+,x--; else { printf("%d step(s) before a loop of %d step(s)\n",f[x-][y]-,f[x][y]-f[x-][y]+); break; } }
if (a[x][y]=='E') { if (y==m) { printf("%d step(s) to exit\n",f[x][y]); break; } if (!f[x][y+]) f[x][y+]=f[x][y]+,y++; else { printf("%d step(s) before a loop of %d step(s)\n",f[x][y+]-,f[x][y]-f[x][y+]+); break; } }
if (a[x][y]=='S') { if (x==n) { printf("%d step(s) to exit\n",f[x][y]); break; } if (!f[x+][y]) f[x+][y]=f[x][y]+,x++; else { printf("%d step(s) before a loop of %d step(s)\n",f[x+][y]-,f[x][y]-f[x+][y]+); break; } }
if (a[x][y]=='W') { if (y==) { printf("%d step(s) to exit\n",f[x][y]); break; } if (!f[x][y-]) f[x][y-]=f[x][y]+,y--; else { printf("%d step(s) before a loop of %d step(s)\n",f[x][y-]-,f[x][y]-f[x][y-]+); break; } }
}
}
return ;
}

  2993&&2996 两道题刚好相反,是一个模拟棋盘的问题。

  但主要是有一些没有任何用处的东西(+,-,|)影响了正常的操作。

  注意下细节以及题意,多打几次就A了

  2993CODE

#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
char a[][]=
{
{'+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+'},
{'|','.','.','.','|',':',':',':','|','.','.','.','|',':',':',':','|','.','.','.','|',':',':',':','|','.','.','.','|',':',':',':','|'},
{'+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+'},
{'|',':',':',':','|','.','.','.','|',':',':',':','|','.','.','.','|',':',':',':','|','.','.','.','|',':',':',':','|','.','.','.','|'},
{'+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+'},
{'|','.','.','.','|',':',':',':','|','.','.','.','|',':',':',':','|','.','.','.','|',':',':',':','|','.','.','.','|',':',':',':','|'},
{'+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+'},
{'|',':',':',':','|','.','.','.','|',':',':',':','|','.','.','.','|',':',':',':','|','.','.','.','|',':',':',':','|','.','.','.','|'},
{'+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+'},
{'|','.','.','.','|',':',':',':','|','.','.','.','|',':',':',':','|','.','.','.','|',':',':',':','|','.','.','.','|',':',':',':','|'},
{'+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+'},
{'|',':',':',':','|','.','.','.','|',':',':',':','|','.','.','.','|',':',':',':','|','.','.','.','|',':',':',':','|','.','.','.','|'},
{'+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+'},
{'|','.','.','.','|',':',':',':','|','.','.','.','|',':',':',':','|','.','.','.','|',':',':',':','|','.','.','.','|',':',':',':','|'},
{'+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+'},
{'|',':',':',':','|','.','.','.','|',':',':',':','|','.','.','.','|',':',':',':','|','.','.','.','|',':',':',':','|','.','.','.','|'},
{'+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+'},
};
string s1,s2;
inline void white(string s)
{
while (s.size())
{
string temp="";
for (int i=;i<=s.find(",");++i)
temp+=s[i];
if (temp[]>='A'&&temp[]<='Z') a[(-temp[]+''+)*-][(temp[]-'a'+)*-]=temp[],s.erase(,); else a[(-temp[]+''+)*-][(temp[]-'a'+)*-]='P',s.erase(,);
}
}
inline void black(string s)
{
while (s.size())
{
string temp="";
for (int i=;i<=s.find(",");++i)
temp+=s[i];
if (temp[]>='A'&&temp[]<='Z') a[(-temp[]+''+)*-][(temp[]-'a'+)*-]=temp[]-'A'+'a',s.erase(,); else a[(-temp[]+''+)*-][(temp[]-'a'+)*-]='p',s.erase(,);
}
}
int main()
{
cin>>s1; cin>>s2; s2+=',';
if (s1[]=='W') white(s2); else black(s2);
cin>>s1; cin>>s2; s2+=',';
if (s1[]=='W') white(s2); else black(s2);
for (int i=;i<;++i)
{
for (int j=;j<;++j)
putchar(a[i][j]);
putchar('\n');
}
return ;
}

  2996CODE

#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
string a[],s;
int i,j;
int main()
{
cin>>s;
for (i=;i<=;++i)
cin>>a[i],cin>>s;
printf("White: ");
for (i=;i;--i)
for (j=;j<a[i].size();++j)
if (a[i][j]=='K') printf("K%c%d",'a'+(j+)/-,-i+);
for (i=;i;--i)
for (j=;j<a[i].size();++j)
if (a[i][j]=='Q') printf(",Q%c%d",'a'+(j+)/-,-i+);
for (i=;i;--i)
for (j=;j<a[i].size();++j)
if (a[i][j]=='R')
printf(",R%c%d",'a'+(j+)/-,-i+);
for (i=;i;--i)
for (j=;j<a[i].size();++j)
if (a[i][j]=='B')
printf(",B%c%d",'a'+(j+)/-,-i+);
for (i=;i;--i)
for (j=;j<a[i].size();++j)
if (a[i][j]=='N') printf(",N%c%d",'a'+(j+)/-,-i+);
for (i=;i;--i)
for (j=;j<a[i].size();++j)
if (a[i][j]=='P')
printf(",%c%d",'a'+(j+)/-,-i+);
printf("\nBlack: ");
for (i=;i<=;++i)
for (j=;j<a[i].size();++j)
if (a[i][j]=='k') printf("K%c%d",'a'+(j+)/-,-i+);
for (i=;i<=;++i)
for (j=;j<a[i].size();++j)
if (a[i][j]=='q') printf(",Q%c%d",'a'+(j+)/-,-i+);
for (i=;i<=;++i)
for (j=;j<a[i].size();++j)
if (a[i][j]=='r')
printf(",R%c%d",'a'+(j+)/-,-i+);
for (i=;i<=;++i)
for (j=;j<a[i].size();++j)
if (a[i][j]=='b')
printf(",B%c%d",'a'+(j+)/-,-i+);
for (i=;i<=;++i)
for (j=;j<a[i].size();++j)
if (a[i][j]=='n') printf(",N%c%d",'a'+(j+)/-,-i+);
for (i=;i<=;++i)
for (j=;j<a[i].size();++j)
if (a[i][j]=='p')
printf(",%c%d",'a'+(j+)/-,-i+);
return ;
}

  最后发现我模拟题的代码都是复制来复制去的,导致程序看起来很。。。(臃肿)

  下次还是尽量多清晰的分块吧

POJ 1068&&2632&&1573&&2993&&2996的更多相关文章

  1. 模拟 POJ 1068 Parencodings

    题目地址:http://poj.org/problem?id=1068 /* 题意:给出每个右括号前的左括号总数(P序列),输出每对括号里的(包括自身)右括号总数(W序列) 模拟题:无算法,s数组把左 ...

  2. poj 1068 模拟

    题目链接 大概题意就是告诉你有个n个小括号,每一个")"左边有多少个"("都告诉你了,然后让你求出每一对括号之间有多少对括号(包含自己本身). 思路: 我先计算 ...

  3. POJ 1068

    http://poj.org/problem?id=1068 这道题是一道模拟的题目 题目大意呢,p代表前面的'('的个数,而w代表这个括号所包括的括号的个数: 给你p,要你求w: 解题思路: 首先, ...

  4. POJ 1068 Parencodings 模拟 难度:0

    http://poj.org/problem?id=1068 #include<cstdio> #include <cstring> using namespace std; ...

  5. poj 1068 Parencodings(栈)

    题目链接:http://poj.org/problem?id=1068 思路分析:对栈的模拟,将栈中元素视为广义表,如 (((()()()))),可以看做 LS =< a1, a2..., a1 ...

  6. POJ 1068 Parencodings【水模拟--数括号】

    链接: http://poj.org/problem?id=1068 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#probl ...

  7. poj 1068 Parencodings(模拟)

    转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj ...

  8. POJ 1068 AC 2014-01-07 15:24 146人阅读 评论(0) 收藏

    POJ的题目都是英文的,所以,,,还是直接贴代码吧 #include<stdio.h> int main(){ int x,y,z; int n,nm,max; scanf("% ...

  9. POJ 1068 Parencodings (类似括号的处理问题)

                                                                                                    Pare ...

随机推荐

  1. 加速JDBC的快捷方法

    JAVA 应用必须通过 JDBC 从数据库中取数,有时候我们会发现,数据库的负担一点也不重而且 SQL 很简单,但取数的速度仍然很慢.仔细测试会发现,性能瓶颈主要在 JDBC 上,比如 MySQL 的 ...

  2. 【Redis】Redis学习(一) Redis初步入门

    一.Redis基础知识 1.1 Redis简介 Redis是一个开源(BSD许可),内存存储的数据结构服务器,可用作数据库,高速缓存和消息队列代理.它支持字符串.哈希表.列表.集合.有序集合,位图,h ...

  3. GenyMotion the virtual device got no ip address 问题解决

    不要再找答案了 升级你的virtual box到最新版本(目前是 5.0.26,已通过) 如果你是windows 10系统 必须关闭hyper-v 在管理员命令行下运行bcdedit /set hyp ...

  4. Prometheus Node_exporter 之 Node Exporter

    Node Exporter 1. Node Exporter Scrape Time type: GraphUnit: secondsLabel: Seconds{{collector}} - 各个收 ...

  5. python的函数(二)

    1,函数的变量 2,函数的返回值 1,函数的变量 1.0,函数的变量分为局部变量和全局变量. def fun(): x = 100 print x 这个x是局部变量,函数执行完后,x的变量就会销毁,只 ...

  6. 转:在ASP.NET MVC中通过URL路由实现对多语言的支持

    对于一个需要支持多语言的Web应用,一个很常见的使用方式就是通过请求地址来控制界面呈现所基于的语言文化,比如我们在表示请求地址的URL中将上语言文化代码(比如en或者en-US)来指导服务器应该采用怎 ...

  7. ZooKeeper 集群的安装部署

    0. 说明 ZooKeeper 安装在 s102.s103.s104上,这三个节点同时是 Hadoop 的 DataNode 1. ZooKeeper 本地模式安装配置 1.0 在 s101 上进行安 ...

  8. pt-table-checksum工具MySQL主从复制数据一致性

    所使用的工具是pt-table-checksum 原理是: 在主上执行检查语句去检查 mysql主从复制的一致性,生成 replace 语句,然后通过复制传递到从库,再通过update 更新 mast ...

  9. jQuery 1.11 / 2.1 beta 版发布

    jQuery开发团队近日发布了jQuery 1.11和2.1的beta版本. jQuery 1.x版本支持IE 6/7/8,jQuery 2.x 不支持,如果你已经抛弃了IE 6/7/8用户,可以升级 ...

  10. Linux核心-hc课堂笔记

    windows系统:分区 linux系统:树形结构 <鸟哥的私房菜>关于分区.linux命令.基础篇  服务器篇 关于文件夹: /boot       引导分区,操作系统启动时要到该目录下 ...