【toj1312】The Game
来源:互联网 发布:淘宝 各地博物馆 编辑:程序博客网 时间:2024/05/18 11:26
//时隔一年,再次做这个题,有一种不一样的感觉。。。 #include <cstdio>int a[50][50] = {0};int d[4][2] = {1,0, 1,1, 0,1, -1,1};bool dfs(int x, int y, int dir, int col, int s) {int xx = x + d[dir][0], yy = y + d[dir][1];if (s == 5) return (a[xx][yy] != col);return a[xx][yy] == col && dfs(xx, yy, dir, col, ++s);}void gao() {for (int i = 10; i < 29; ++i)for (int j = 10; j < 29; ++j)if (a[i][j]) {for (int k = 0; k < 4; ++k) {if (a[i-d[k][0]][j-d[k][1]] != a[i][j] && dfs(i, j, k, a[i][j], 1)){printf("%d\n%d %d\n", a[i][j], i-9, j-9);return;} }//for }//if puts("0");}int main() {int T;scanf(" %d", &T);while (T--) {for (int i = 10; i < 29; ++i)for (int j = 10; j < 29; ++j)scanf(" %d", &a[i][j]);gao();}return 0;}
去年我是这么写的...
#include <iostream>using namespace std;int fun(int a[][30], int i, int j){if(a[i][j] == 1 && a[i][j + 1] == 1 && a[i][j + 2] == 1 && a[i][j + 4] == 1 && a[i][j + 3] == 1 && a[i][j + 5] != 1 && a[i][j - 1] != 1)return 1;else if(a[i][j] == 2 && a[i][j + 1] == 2 && a[i][j + 2] == 2 && a[i][j + 4] == 2 && a[i][j + 3] == 2 && a[i][j + 5] != 2 && a[i][j - 1] != 2) return 2;else if(i >= 4 && a[i][j] == 1 && a[i - 1][j + 1] == 1 && a[i - 2][j + 2] == 1 && a[i - 4][j + 4] == 1 && a[i - 3][j + 3] == 1 && a[i - 5][j + 5] != 1&& a[i + 1][j - 1] != 1)return 1;else if(i >= 4 && a[i][j] == 2 && a[i - 1][j + 1] == 2 && a[i - 2][j + 2] == 2 && a[i - 4][j + 4] == 2 && a[i - 3][j + 3] == 2 && a[i - 5][j + 5] != 2&& a[i + 1][j - 1] != 2)return 2;else if(a[i][j] == 2 && a[i + 1][j] == 2 && a[i + 2][j] == 2 && a[i + 4][j] == 2 && a[i + 3][j] == 2 && a[i + 5][j] != 2 && a[i - 1][j] != 2) return 2;else if(a[i][j] == 1 && a[i + 1][j] == 1 && a[i + 2][j] == 1 && a[i + 4][j] == 1 && a[i + 3][j] == 1 && a[i + 5][j] != 1 && a[i - 1][j] != 1)return 1;else if(a[i][j] == 1 && a[i + 1][j + 1] == 1 && a[i + 2][j + 2] == 1 && a[i + 3][j + 3] == 1 && a[i + 4][j + 4] == 1 && a[i + 5][j + 5] != 1 && a[i - 1][j - 1] != 1)return 1;else if(a[i][j] == 2 && a[i + 1][j + 1] == 2 && a[i + 2][j + 2] == 2 && a[i + 3][j + 3] == 2 && a[i + 4][j + 4] == 2 && a[i + 5][j + 5] != 2 && a[i - 1][j - 1] != 2)return 2;return 0;}int main(){int n;cin >> n;while(n--){int a[30][30] = {0};for(int i = 1; i < 20; i++){for(int j = 1; j < 20; j++)cin >> a[i][j];}bool flag = true;for(int i = 1; i < 20; i++){for(int j = 1; j < 20; j++){if(fun(a, i, j) == 1){cout << "1" << endl;cout << i << " " << j << endl;flag = false;break;}else if(fun(a, i, j) == 2){cout << "2" << endl;cout << i << " " << j << endl;flag = false;break;}}if(!flag)break;}if(!flag)continue;cout << "0" << endl;}return 0;}
0 0
- 【toj1312】The Game
- The Game
- The Game
- The Game
- The Game
- The Computer Game Dogma
- fjnu 1083 The Game
- The four number game
- poj1101 The Game
- POJ 1101 The Game
- poj 1101 The Game
- poj 1101 The Game
- poj 1101 The Game
- The rule of game
- 1101 The Game
- 【水题】poj1970 The Game
- poj 1101 The Game
- POJ 1101 - The Game
- response细节
- [蓝桥杯][Java] 有趣儿的平方数
- 设计模式之结构型模式
- 使用log4j把日志记录到不同文件
- 【python学习.第五周任务】
- 【toj1312】The Game
- 第十四周OJ
- 字符串-05. 字符串循环左移(20)(部分对)
- 周伯通招聘发现频道之追梦网
- Problem 013——UVa 10474 - Where is the Marble?
- 用Python开始机器学习(10:聚类算法之K均值)
- 两个数组相加
- 第14周项目2-带姓名的成绩单(2)
- 《非计算机毕业生2015互联网校招求职之路》2014-10-15