哈理工OJ 1031 _OOOO_ Problem(简单模拟问题)
来源:互联网 发布:js年龄正则表达式 编辑:程序博客网 时间:2024/04/29 08:30
OOOO Problem
Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 288(96 users) Total Accepted: 90(83 users) Rating: Special Judge: No
Description
Do you know Gobang?
There is a 15 * 15 board and two players drop piece of white or black one by one.
We define a pattern of “+OOOO+” as “Huo 4”.
‘O’ means the piece of you.
‘X’ means the piece of your opponent.
‘+’ means the blank space of the board.
How many “Huo 4” belonging to you in the board ?
Input
Line 1 : A integer T which means there are T test cases following seperated by a blank line.
For each test case, the input will show a 15 * 15 board.
Output
For each test case, output the answer in a line.
Sample Input
2
+++++++++++++++
++OOOO++++++O++
++++++++++++O++
++++++++++++O++
++O+++++++++O++
+++O+++++++++++
++++O++++++++++
+++++O++++++O++
+++++++++++O+++
++++++++++O++++
+++++++++O+++++
+++++++++++++++
+++++++++++++++
+++++++++++++++
+++++++++++++++
++++++++++++X++
++OOOOX+++++O++
++++++++++++O++
++++++++++++O++
++O+++++++++O++
+++O+++++++++++
++++O++++++++X+
+++++O++++++O++
++++++X++++O+++
++++++++++O++++
+++++++++O+++++
+++++++++++++++
+++++++++++++++
+XXXX++++++++++
+++++++++++++++
Sample Output
4
0
本题很简单,看样例就能猜出题目所求是什么。
下面大致说下我的思路吧,假如某个点是“O”,就从这个点为起点开始查找。
看能不能找到符合条件的图形,另外,八个方向只需要找四个就可以了,至于为什么,自己试着思考一下。
下面是AC代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;char a[20][20];int check(int i,int j,int k,int l,int m){ if(i<0||i>=15||j<0||j>=15||k<0||k>=15||l<0||l>=15||m<0||m>15) { return 0; } return 1;}int main(){ int t; scanf("%d",&t); while(t--) { for(int i=0;i<15;i++) { scanf("%s",&a[i]); } int sum=0; for(int i=0;i<15;i++) { for(int j=0;j<15;j++) { if(a[i][j]=='O') { if(check(i-1,i+1,i+2,i+3,i+4)&&a[i-1][j]=='+'&&a[i+1][j]=='O'&&a[i+2][j]=='O'&&a[i+3][j]=='O'&&a[i+4][j]=='+') { sum++; } if(check(j-1,j+1,j+2,j+3,j+4)&&a[i][j-1]=='+'&&a[i][j+1]=='O'&&a[i][j+2]=='O'&&a[i][j+3]=='O'&&a[i][j+4]=='+') { sum++; } if(check(i+1,j-1,i-1,j+1,i-2)&&check(j+2,i-3,j+3,i-4,j+4)&&a[i+1][j-1]=='+'&&a[i-1][j+1]=='O'&&a[i-2][j+2]=='O'&&a[i-3][j+3]=='O'&&a[i-4][j+4]=='+') { sum++; } if(check(i-1,j-1,i+1,j+1,i+2)&&check(j+2,i+3,j+3,i+4,j+4)&&a[i-1][j-1]=='+'&&a[i+1][j+1]=='O'&&a[i+2][j+2]=='O'&&a[i+3][j+3]=='O'&&a[i+4][j+4]=='+') { sum++; } } } } printf("%d\n",sum); } return 0;}
- 哈理工OJ 1031 _OOOO_ Problem(简单模拟问题)
- 哈理工OJ 1045 Draw A Square(简单模拟)
- 哈理工OJ 2111 Apple(简单模拟)
- hrbust 哈理工oj 1020 Robot Motion【简单模拟】
- 哈理工OJ 1936 PROBLEM-4SS(二分法解题)
- 哈理工OJ 1562 字符统计器(水模拟)
- 哈理工oj 1000 A+B problem
- hrbust 哈理工oj 1330 邂逅【模拟】
- 哈理工 OJ 2215 Angle(简单的思维题)
- 哈理工OJ 2214 Judge(简单的数学题)
- 哈理工OJ 1124 Final Destination(简单递推)
- 哈理工OJ 1986 大悲咒(简单递推)
- 【NOI OJ】1455 An Easy Problem(简单模拟题)
- 哈理工OJ 2003 棋盘(dp问题)
- 哈理工OJ 2033 A Funny Game(博弈问题)
- 哈理工OJ 1597 序列问题II(水DP)
- 哈理工OJ 2002 幂集(DP问题)
- 哈理工OJ 2004 整数划分(整数划分问题)
- HDU 1083 Courses(二分图,匈牙利算法)
- Java设计模式
- jquery对象和js的dom对象之间的转换
- UItextField
- Oracle 动态性能视图之V$LOCK
- 哈理工OJ 1031 _OOOO_ Problem(简单模拟问题)
- mysql中如何获取当前时间以及对时间的处理函数
- HTML 中thead tbody tfoot 的使用方法
- HDU 3078 Network 在线LCA
- 秀场直播风头正劲,网易视频云助力破除音视频技术壁垒
- EJS模板介绍
- ArrayList和LinkedList的区别,Hashtable和HashMap类的区别?
- arm-linux交叉编译ACE
- Q8、旋转数组的最小数字