【题意简述】:矩阵中除了‘.’仅仅能出现一种符号。是这些之中的一个‘‑’, ‘|’, ‘\’, or ‘/’,并且就是当除了‘.’之外还仅仅有一种符号时。这个符号还必须连成一条直线,否则就是错的,这个时候就能够输出CORRECT。否则当有两种以上符号的时候。就是错误。

还有就是当仅仅有‘.’时,也是不正确的。

【分析】:模拟过程,将整个思路想清晰。

本代码參考:http://www.cnblogs.com/gongling/archive/2012/08/05/2623676.html。

// 208K 125ms
#include<cstdio>
#include<iostream>
using namespace std;
#define MAX_LEN 101
#define is_valid(x, y) ((x)>=0 && (x)<N && (y)>=0 && (y)<M)
int N, M;
char image[MAX_LEN][MAX_LEN];
int visited[MAX_LEN][MAX_LEN];
int flag; void mark(int i, int j, int dx, int dy, char ch)
{
while(is_valid(i+dx, j+dy) && image[i+dx][j+dy]==ch)
{
visited[i+dx][j+dy] = 1;
i += dx;
j += dy;
}
} void solve()
{
int i, j;
char ch;
for(i=0; i<N; i++)
{
for(j=0; j<M; j++)
{
ch = image[i][j];
if(ch!='.' && !visited[i][j])
{
visited[i][j] = 1;
switch(ch)
{
case '-':
++flag;
mark(i, j, 0, 1, ch);
break;
case '|':
++flag;
mark(i, j, 1, 0, ch);
break;
case '\\':
++flag;
mark(i, j, 1, 1, ch);
break;
case '/':
++flag;
mark(i, j, 1, -1, ch);
break;
}
}
}
}
} int main()
{
int i, tests;
scanf("%d", &tests);
while(tests--)
{
scanf("%d %d", &N, &M);
for(i=0; i<N; i++)
scanf("%s", image[i]);
memset(visited, 0, sizeof(visited));
flag = 0;
solve();
if(flag == 1)
printf("CORRECT\n");
else
printf("INCORRECT\n");
}
}

POJ 3561 Pseudographical recognizer的更多相关文章

  1. 字符串专题:KMP POJ 3561

    http://poj.org/problem?id=3461 KMP这里讲的不错next的求法值得借鉴 http://blog.sina.com.cn/s/blog_70bab9230101g0qv. ...

  2. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  3. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  4. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  5. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  6. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  7. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  8. POJ 2255. Tree Recovery

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 De ...

  9. POJ 2752 Seek the Name, Seek the Fame [kmp]

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Ac ...

随机推荐

  1. HDU 多校1.8

  2. HDU 2256 Problem of Precision (矩阵快速幂)(推算)

    Problem of Precision Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  3. luogu P1325 雷达安装

    题目描述 描述: 假设海岸线是一条无限延伸的直线.它的一侧是陆地,另一侧是海洋.每一座小岛是在海面上的一个点.雷达必须安装在陆地上(包括海岸线),并且每个雷达都有相同的扫描范围d.你的任务是建立尽量少 ...

  4. 【二分答案】【Heap-Dijkstra】bzoj2709 [Violet 1]迷宫花园

    显然最短路长度随着v的变化是单调的,于是可以二分答案,据说spfa在网格图上表现较差. #include<cstdio> #include<cstring> #include& ...

  5. 自定义数据类型写入SequenceFile并读出

    开头对这边博客的内容做个概述,首先是定义了一个DoubleArrayWritable的类,用于存放矩阵的列向量,然后将其作为value写入SequenceFile中,key就是对应的矩阵的列号,最后( ...

  6. Linux Hook 笔记

    相信很多人对"Hook"都不会陌生,其中文翻译为"钩子".在编程中, 钩子表示一个可以允许编程者插入自定义程序的地方,通常是打包好的程序中提供的接口. 比如,我 ...

  7. java工具类获取properties文件的配置

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.i ...

  8. .net 多文件上传

    版权声明:本文为博主原创文章,未经博主允许不得转载. 1.页面 <head runat="server"> <title>上传文件</title> ...

  9. jquery给input标签添加data-options属性

    //原生JS实现document.getElementById('startPrice').setAttribute("data-options", "required: ...

  10. Coherence代理的负载均衡

    Coherence在extend模式下,proxy的负载均衡机制官方解释是 Extend client connections are load balanced across proxy servi ...