POJ 1970 The Game
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 6886 | Accepted: 1763 |
Description
Horizontal lines are marked 1, 2, ..., 19 from up to down and vertical lines are marked 1, 2, ..., 19 from left to right.
The objective of this game is to put five stones of the same color consecutively along a horizontal, vertical, or diagonal line. So, black wins in the above figure. But, a player does not win the game if more than five stones of the same color were put consecutively.
Given a configuration of the game, write a program to determine whether white has won or black has won or nobody has won yet. There will be no input data where the black and the white both win at the same time. Also there will be no input data where the white or the black wins in more than one place.
Input
Output
Sample Input
1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 2 0 0 2 2 2 1 0 0 0 0 0 0 0 0 0 0
0 0 1 2 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 0 1 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 2 2 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 2 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Sample Output
1
3 2
Source
思路:搜索。
#include<iostream>
using namespace std;
const int dir_x[]={,,,-};
const int dir_y[]={,,,};
void search(int x,int y);
int judge,goal_x,goal_y,board[][];
void search(int x,int y){
for(int i=;i<;i++){
int tmpx=x,tmpy=y,counter=;
int tx=tmpx-dir_x[i],ty=tmpy-dir_y[i];
if(tx>=&&tx<&&ty>=&&ty<&&board[tx][ty]==board[x][y]) continue;
while(tmpx>=&&tmpx<&&tmpy>=&&tmpy<&&board[tmpx][tmpy]==board[x][y]){
counter++;
tmpx+=dir_x[i];
tmpy+=dir_y[i];
}
if(counter==){
judge=board[x][y];
goal_x=x+; goal_y=y+;
return;
}
}
return;
}
int main(){
int t;cin>>t;
while(t--){
for(int i=;i<;i++)
for(int j=;j<;j++)
cin>>board[i][j];
judge=;
for(int i=;i<;i++){
if(judge!=) break;
for(int j=;j<;j++){
if(judge!=) break;
if(board[i][j]==) continue;
search(i,j);
}
}
cout<<judge<<endl;
if(judge==)cout<<goal_x<<" "<<goal_y<<endl;
else if(judge==) cout<<goal_x<<" "<<goal_y<<endl;
}
}
最新文章
- mysqldump 逻辑备份的正确姿势
- 【转】从 ArcGIS for Desktop 发布地图服务
- JSON、使用JSON进行数据交换的基础和原理
- 转载:Source Insight查看ARM汇编源程序 &;&; 高亮显示程序 &;&; Source Insight打开project窗口出错
- Java Web开发 - 持久型/存储型XSS漏洞
- 利用jdbc简单封装一个小框架(类似DBUtils)
- Java Web项目(Extjs)报错四
- 20175305张天钰《java程序设计》第五周学习总结
- virtualbmc 使用
- OSGi HelloWorld
- Codeforces 1037D【BFS】
- 着色器shaders
- stm32中adc的常规通道和注入通道的区别
- eclipse下搭建shell脚本编辑器--安装开发shell的eclipse插件shelled
- web网站的并发量级别
- AcWing 143. 最大异或对
- 在 ASP.NET Core 具体使用文档
- OD 实验(九) - 对一个程序的破解
- 【BZOJ 1478】 1478: Sgu282 Isomorphism (置换、burnside引理)
- Git学习环境搭建和git对用户的增删改查命令