zoj3944 暴力搜

省赛I题,感觉这题做出来就已经可以铜牌了...好怪的题目,感觉省赛都是挺简单,但是挺容易犯错的题

题目要求找出所有的人,

/*
OOO
OOO
OOO
*/

想上面这种所有都是头的竟然就算了9个人,将一个器官的周围可能的情况都尽量归为一个点

遍历每个节点,附件器官清零,遍历模拟的时候还是挺容易犯错的,特别是‘\‘这种,我就忘了把‘(‘讨论了,wa了三次

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>

const int inf= (1<<31)-1;
const int MAXN = 1e2+10;

using namespace std;

char g[MAXN][MAXN];

int n,m;

int check(int x,int y){
    if(x<1||y<1||x>n||y>m)return 0;
    else return 1;
}
/*
OOO
OOO
OOO
*/
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++){
            scanf("%s",g+i);
            for(int j=m;j>=1;j--)
                g[i][j] = g[i][j-1];
        }
        /*for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++)
                printf("%c\n",g[i][j]);
            cout<<endl;
        }*/
        int sum=0;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if(g[i][j]==‘O‘){
                    sum+= 1;
                   // cout<<sum<<endl;
                    if(check(i+1,j)&&g[i+1][j]==‘|‘){
                        g[i+1][j] = ‘.‘;
                    }if(check(i+1,j-1)&&g[i+1][j-1]==‘/‘){
                        g[i+1][j-1] = ‘.‘;
                    }if(check(i+1,j+1)&&g[i+1][j+1]==‘\\‘){
                        g[i+1][j+1] = ‘.‘;
                    }if(check(i+2,j-1)&&g[i+2][j-1]==‘(‘){
                        g[i+2][j-1] = ‘.‘;
                    }if(check(i+2,j+1)&&g[i+2][j+1]==‘)‘){
                        g[i+2][j+1] = ‘.‘;
                    }
                }else if(g[i][j]==‘|‘){
                    sum+=1;
                    if(check(i,j+1)&&g[i][j+1]==‘\\‘){
                        g[i][j+1] = ‘.‘;
                    }if(check(i+1,j-1)&&g[i+1][j-1]==‘(‘){
                        g[i+1][j-1] = ‘.‘;
                    }if(check(i+1,j+1)&&g[i+1][j+1]==‘)‘){
                        g[i+1][j+1] = ‘.‘;
                    }
                }else if(g[i][j]==‘/‘){
                    sum+=1;
                    if(check(i,j+1)&&g[i][j+1]==‘|‘){
                        g[i][j+1] = ‘.‘;
                    }if(check(i,j+2)&&g[i][j+2]==‘\\‘){
                        g[i][j+2] = ‘.‘;
                    }if(check(i+1,j)&&g[i+1][j]==‘(‘){
                        g[i+1][j] = ‘.‘;
                    }if(check(i+1,j+2)&&g[i+1][j+2]==‘)‘){
                        g[i+1][j+2] = ‘.‘;
                    }
                }else if(g[i][j]==‘\\‘){
                    sum+=1;
                    if(check(i+1,j)&&g[i+1][j]==‘)‘)
                        g[i+1][j] = ‘.‘;
                    if(check(i+1,j-2)&&g[i+1][j-2]==‘(‘) //error prone
                        g[i+1][j-2] = ‘.‘;
                }else if(g[i][j]==‘(‘){
                      sum+=1;
                      if(check(i,j+2)&&g[i][j+2]==‘)‘)
                            g[i][j+2] = ‘.‘;
                }else if(g[i][j]==‘)‘){
                        sum+=1;
                }
            }
        }
        printf("%d\n",sum);
    }
    //cout << "Hello world!" << endl;
    return 0;
}

时间: 2024-08-12 03:22:38

zoj3944 暴力搜的相关文章

hdu1814 2-SAT 暴力搜

Peaceful Commission Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2853    Accepted Submission(s): 901 Problem Description The Public Peace Commission should be legislated in Parliament of The

POJ 1129 Channel Allocation(暴力搜--涂色问题)

Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13295   Accepted: 6806 Description When a radio station is broadcasting over a very large area, repeaters are used to retransmit the signal so that every receiver has a s

hdu1015 dfs暴力搜

很水的题吧,不过以后注意环这种要考虑头尾情况 为了省力素数表范围打错了,太坑了 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <string> #include <queue> #include <stack> #include <algorithm

hdu1015 dfs暴力搜索所有情况模板

脑子有点坑,不知道为什么,可能以前遇到阴影了,现在看到dfs暴力搜有种莫名的害怕,总结一下模板吧 这题还是没意思的,直接暴力搜,不过我写的很烂,可能就是这个原因吧,看了别人的模板,觉得不错. 学了个单词”lexicography“ 字典序,又吃了没文化的亏,wa一次 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath>

UVA 10010-- Where&#39;s Waldorf?--暴力串处理

 Where's Waldorf?  Given a m by n grid of letters, ( ), and a list of words, find the location in the grid at which the word can be found. A word matches a straight, uninterrupted line of letters in the grid. A word can match the letters in the grid

2017ecjtu-summer training # 9 HDU 4544

湫湫系列故事--消灭兔子 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 2992    Accepted Submission(s): 987 Problem Description 湫湫减肥 越减越肥! 最近,减肥失败的湫湫为发泄心中郁闷,在玩一个消灭免子的游戏. 游戏规则很简单,用箭杀死免子即可. 箭是一种消耗品,已知有M种不同类型

Sa yo na ra

总想记点些什么. 都快忘了当初是为什么来到这里呢... 2014年10月,友人给我介绍了一门编程竞赛ACM,并给我演示了一下A+B.于是我知道了ACM的含义. 2014年12月,开始水入门题. 2015年1月,第一次参加校赛,在萌新堆中求生存. 2015年2月,看紫书,学算法. 回校后就断断续续地参加一些比赛,成功入坑. 5月,去大连吹海风,吹来了省赛一等奖. 之后就是最要感谢的那个暑假.感谢昌神和学长在大家集体回家度假之时依然在401陪伴着我刷题,以及感谢麟神给我的建议,我也是在那时候学会了很

四方定理(洛谷 1586)

题目描述 四方定理是众所周知的:任意一个正整数n,可以分解为不超过四个整数的平方和.例如:25=12+22+22+42,当然还有其他的分解方案,25=42+32和25=52.给定的正整数n,编程统计它能分解的方案总数.注意:25=42+32和25=32+42视为一种方案. 输入输出格式 输入格式: 第一行为正整数t(≤100),接下来t行,每行一个正整数n(≤32768). 输出格式: 对于每个正整数n,输出方案总数. 输入输出样例 输入样例#1: 1 2003 输出样例#1: 48 /* 先用

maximum sum

uva,10684 1 #include <iostream> 2 #include <cstdio> 3 #define maxn 10005 4 using namespace std; 5 6 int main() 7 { 8 int n; 9 int a[maxn]; 10 while(scanf("%d",&n),n) 11 { 12 for(int i=0;i<n;i++) 13 scanf("%d",&a[