题目描述五虎棋是流传在东北民间的一种游戏,GG小的时候,经常被表哥虐得很惨。 o...o ..... ..o.. ..... o...o 五虎(5分): o.o .o. o.o 通天(5分): ..... ..o.. o.... ooooo ..o.. .o... ..... ..o.. ..o.. ..... ..o.. ...o. ..... ..o.. ....o 四斜(4分): ...o. ..... ..... .o... ..o.. o.... ....o ..o.. .o... .o... ...o. ...o. o.... ..o.. ..o.. ....o ..... ...o. .o... ..... 三斜(3分): ..o.. ..... ..... ..o.. .o... ..... ..... ...o. o.... o.... ....o ....o ..... .o... ...o. ..... ..... ..o.. ..o.. ..... 小斗(1分): oo oo 例1 o...o .o.o. ..o.. .oooo o..oo o这名玩家形成了 1个大五虎(10分), 1个小五虎(5分), 2个通天(10分), 1个小斗(1分). 总分:10 + 5 + 10*2 + 1 = 36 .o.o. o.o.o .o.o. o.o.o .o.o. o这名玩家形成了 4个小五虎, 4个四斜 总分 5*4 + 4*4 = 36 输入多组测试数据。首先是一个整数T ( 1 ≤ T ≤ 10000 ),占一行,表示测试数据的组数. 输出对于每组测试数据,输出一行. 结果为两个整数,之间用一个空格隔开,分别表示先手(x)的得分,和后手(o)的得分。 样例输入2 oxxxo xoxox xxoxx xoooo oxxoo xoxox oxoxo xoxox oxoxo xoxox 样例输出9 26 57 36 |
简单模拟
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; char mat[10][10]; int map[10][10]; int big_five(int r) { if(map[0][0] == r && map[0][4] == r && map[2][2] == r && map[4][0] == r && map[4][4] == r) return 10; return 0; } int five(int r) { int i,j,sum = 0; for(i = 0; i<=2; i++) { for(j = 0; j<=2; j++) { if(map[i][j] == r && map[i][j+2] == r && map[i+1][j+1] == r && map[i+2][j] == r && map[i+2][j+2] == r) sum+=5; } } return sum; } int air(int r) { int i,sum = 0; for(i = 0; i<5; i++) if(map[i][0]==r && map[i][1] == r && map[i][2] == r && map[i][3] == r && map[i][4] == r) sum+=5; for(i = 0; i<5; i++) if(map[0][i]==r && map[1][i] == r && map[2][i] == r && map[3][i] == r && map[4][i] == r) sum+=5; for(i = 0; i<5; i++) if(map[i][i]!=r) break; if(i == 5) sum+=5; if(map[0][4] == r && map[1][3] == r && map[2][2] == r && map[3][1] == r && map[4][0] == r) sum+=5; return sum; } int four(int r) { int sum = 0; if(map[0][3] == r && map[1][2] == r && map[2][1] == r && map[3][0] == r) sum+=4; if(map[1][0] == r && map[2][1] == r && map[3][2] == r && map[4][3] == r) sum+=4; if(map[1][4] == r && map[2][3] == r && map[3][2] == r && map[4][1] == r) sum+=4; if(map[0][1] == r && map[1][2] == r && map[2][3] == r && map[3][4] == r) sum+=4; return sum; } int three(int r) { int sum = 0; if(map[0][2] == r && map[1][1] == r && map[2][0] == r) sum+=3; if(map[2][0] == r && map[3][1] == r && map[4][2] == r) sum+=3; if(map[2][4] == r && map[3][3] == r && map[4][2] == r) sum+=3; if(map[0][2] == r && map[1][3] == r && map[2][4] == r) sum+=3; return sum; } int small(int r) { int i,j,sum = 0; for(i = 0; i<=3; i++) { for(j = 0; j<=3; j++) { if(map[i][j] == r && map[i][j+1] == r && map[i+1][j] == r && map[i+1][j+1] == r) sum+=1; } } return sum; } int main() { int t,i,j; scanf("%d",&t); while(t--) { memset(map,0,sizeof(map)); for(i = 0; i<5; i++) { scanf("%s",mat[i]); for(j = 0; j<5; j++) if(mat[i][j] == 'x') map[i][j] = 1; } int sum1 = 0,sum2 = 0; sum1+=big_five(1); sum2+=big_five(0); sum1+=five(1); sum2+=five(0); sum1+=air(1); sum2+=air(0); sum1+=four(1); sum2+=four(0); sum1+=three(1); sum2+=three(0); sum1+=small(1); sum2+=small(0); printf("%d %d\n",sum1,sum2); } return 0; }
XTU1173:Five Tiger(模拟),布布扣,bubuko.com
原文地址:http://blog.csdn.net/libin56842/article/details/25921939