POJ 1132 Border(边界) 简单模拟
来源:互联网 发布:linux vi 全部删除 编辑:程序博客网 时间:2024/05/29 03:01
这是道简单的模拟题,直接模拟过程便可,关键是找到点的坐标与对应格子的关系。
代码:
#include<stdio.h>#include<string.h>int main(){ char ch[33][33],d; int i,j,x,y,k,n; scanf("%d",&n); k=0; while(n--) { scanf("%d%d",&x,&y); for (i=1;i<=32;i++) for (j=1;j<=32;j++) ch[i][j]='.'; scanf("%c",&d); while(d!='.') { if (d=='E') { x++; ch[32-y+1][x]='X'; } if (d=='N') { y++; ch[32-y+1][x+1]='X'; } if (d=='W') { ch[32-y][x]='X'; x--; } if (d=='S') { ch[32-y+1][x]='X'; y--; } scanf("%c",&d); } k++; printf("Bitmap #%d\n",k); for (i=1;i<=32;i++) { for (j=1;j<=32;j++) printf("%c",ch[i][j]); printf("\n"); } printf("\n"); } return 0;}
但是有一点很奇怪,为什么将以上程序定义的字符数组ch[33][33]改为ch[32][32],
当然其他内容相应地改变,而且也AC了,不过耗时增加了。
前者是:
后者是:
希望大神可以帮我解答一下,谢谢!
改后代码:
#include<stdio.h>#include<string.h>int main(){ char ch[32][32],d; int i,j,x,y,k,n; scanf("%d",&n); k=0; while(n--) { scanf("%d%d",&x,&y); for (i=0;i<=31;i++) for (j=0;j<=31;j++) ch[i][j]='.'; scanf("%c",&d); while(d!='.') { if (d=='E') { ch[31-y+1][x]='X'; x++; } if (d=='N') { y++; ch[31-y+1][x]='X'; } if (d=='W') { ch[31-y][x-1]='X'; x--; } if (d=='S') { ch[31-y+1][x-1]='X'; y--; } scanf("%c",&d); } k++; printf("Bitmap #%d\n",k); for (i=0;i<=31;i++) { for (j=0;j<=31;j++) printf("%c",ch[i][j]); printf("\n"); } printf("\n"); } return 0;}
题目来源:http://poj.org/problem?id=1132
0 0
- POJ 1132 Border(边界) 简单模拟
- 文章标题poj 1132: Border(模拟)
- 什么是简单边界点(Simple border points)
- POJ-1132-Border
- POJ - 1132Border
- POJ 1132 Border 笔记
- poj 1281 MANAGER(简单模拟题)
- poj 2190 简单模拟(ISBN)
- POJ 2000 Gold Coins(简单模拟)
- poj 2509 简单模拟(烟屁换烟)
- POJ 1028 Web Navigation(简单模拟)
- POJ 1250 Tanning Salon(简单模拟)
- POJ 3414 Pots(简单模拟+dfs)
- POJ 2897 Dramatic Multiplications(简单模拟)
- POJ 2632 Crashing Robots(简单模拟)
- POJ 2105 IP Address(简单模拟)
- POJ 3087 (简单map + 模拟)
- POJ 1028(简单的模拟浏览器)
- 在mfc中将信息输出在终端上
- 浅谈对于作用域的理解
- 五个程序员求职者的最佳提问
- 页面间数据传递——委托
- 《Linux》天影linux系列笔记一——linux常用命令详解:ifconfig
- POJ 1132 Border(边界) 简单模拟
- Linux中request_firmware 的用法
- 利用Shape Context进行形状识别
- zoj1134 Strategic Game dp
- mac下配置maven
- C++ unordered_map
- c++ map
- poj1080
- 查找和下载rpm包——http://rpmfind.net/