POJ 1068&&2632&&1573&&2993&&2996
这次的题目是著名的模拟(水逼)专题
题目难度都不大,思维也不深,就是一个字——烦
同时很多题目都有很多坑点
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的更多相关文章
- 模拟 POJ 1068 Parencodings
题目地址:http://poj.org/problem?id=1068 /* 题意:给出每个右括号前的左括号总数(P序列),输出每对括号里的(包括自身)右括号总数(W序列) 模拟题:无算法,s数组把左 ...
- poj 1068 模拟
题目链接 大概题意就是告诉你有个n个小括号,每一个")"左边有多少个"("都告诉你了,然后让你求出每一对括号之间有多少对括号(包含自己本身). 思路: 我先计算 ...
- POJ 1068
http://poj.org/problem?id=1068 这道题是一道模拟的题目 题目大意呢,p代表前面的'('的个数,而w代表这个括号所包括的括号的个数: 给你p,要你求w: 解题思路: 首先, ...
- POJ 1068 Parencodings 模拟 难度:0
http://poj.org/problem?id=1068 #include<cstdio> #include <cstring> using namespace std; ...
- poj 1068 Parencodings(栈)
题目链接:http://poj.org/problem?id=1068 思路分析:对栈的模拟,将栈中元素视为广义表,如 (((()()()))),可以看做 LS =< a1, a2..., a1 ...
- POJ 1068 Parencodings【水模拟--数括号】
链接: http://poj.org/problem?id=1068 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#probl ...
- poj 1068 Parencodings(模拟)
转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj ...
- 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("% ...
- POJ 1068 Parencodings (类似括号的处理问题)
Pare ...
随机推荐
- ionic之angular1.X缓存问题解决
众所周知ionic的angular1.X解决缓存的问题有: 1.在app.js里面修改:默认是true,设置了缓存 .state('tab.msg-main', { url: '/msg-main', ...
- 1.print()与input()
hello world必备->print函数 print(): 作用: 打印函数,打印数据到屏幕中 参数列表: print(value, ..., sep=' ', end='\n', file ...
- 从零自学Java-7.使用数组存储信息
1.创建数组: 2.设置数组的大小: 3.为数组元素赋值: 4.修改数组中的信息: 5.创建多维数组: 6.数组排序. 程序SpaceRemover:显示输入字符串,并将其中所有的空格字符替换为句点字 ...
- LeetCode 题解之Linked List Cycle II
1.题目描述 2.问题分析 使用快慢指针方法判断链表是否有环,然后寻找环开始的节点. 3.代码 ListNode *detectCycle(ListNode *head) { if( head == ...
- 【SPL标准库专题(2)】 Iterator
Iterator界面 本段内容来自阮一峰老师再加自己的部分注解 SPL规定,所有部署了Iterator界面的class,都可以用在foreach Loop中.Iterator界面中包含5个必须部署的方 ...
- Oracle EBS AR 客户API
------------------------------------ 1. Set Environment ------------------------------------ -- 1a. ...
- 如何用SQL脚本在SQL Server Replication中创建合并复制,以及怎么创建分区合并复制
假设我们要创建合并复制的发布端数据库是EFDemo其中有四张表,订阅端数据库是EFDemoSubscription,如下图所示: 首先创建发布端快照代理Sql agent job:"EFDe ...
- C# System.IO.Path
Path的常用方法 函数列表 对一个路径做相应操作,包括文件路径,目录路径,通常会用到Path这个类, 本文列举一些常用的操作. 获取指定路径字符串的目录信息 public static string ...
- ASA5520远程配置 telnet,ssh
telnet配置: ASA5520(config)# passwd asa5520 //创建用户模式密码ASA5520(config)# enable password asa5520 //创建特权模 ...
- NoSQL——not onlySQL不仅仅是SQL
数据有很大一部分是由关系数据库管理系统(RDBMS)来处理. 1970年 E.F.Codd's提出的关系模型的论文 "A relational model of data for large ...