输入输出
程序输入格式
第一行代表棋子颜色1或是2
接下来15行每行15个数字代表了整个棋局0代表为空,1代表黑色棋子,2代表白色棋子
例子如下
2
2 0 0 0 0 1 0 0 0 2 0 1 2 1 2
0 0 0 1 0 0 0 0 0 0 2 1 2 2 2
0 2 0 0 1 1 0 0 0 0 0 0 2 2 1
1 2 1 0 0 1 0 0 2 0 1 0 1 0 0
2 0 2 1 1 0 0 0 0 1 0 0 0 1 1
2 0 1 0 2 2 0 0 0 0 0 0 0 0 2
0 1 0 0 2 2 1 0 0 0 0 0 1 2 1
0 1 1 1 2 1 0 0 2 0 0 0 2 2 1
1 0 1 0 1 0 0 0 0 0 0 0 0 0 1
2 0 0 1 0 1 0 1 2 1 2 0 2 0 1
0 0 2 1 0 2 2 0 0 0 0 0 2 2 0
1 0 2 2 2 1 2 0 0 0 1 0 2 2 0
1 1 0 2 2 1 0 0 0 0 2 0 2 2 1
0 0 1 0 0 0 0 1 1 1 1 0 0 1 0
2 0 2 2 2 0 2 0 2 0 0 0 1 0 1
程序输出格式
程序输出两个数代表落子的行数和列数,数值范围是[1,15]
下面的例子表示程序落子再14行1列
14 1
参考代码
Python3 随机下棋参考代码
import sys
import random
from typing import List
def read() -> (int, List[List[int]]):
f = sys.stdin.read()
data = f.split()
color_ = int(data[0])
result_ = [[0 for j in range(0, 15)] for i in range(0, 15)]
for i in range(0, 15):
for j in range(0, 15):
result_[i][j] = int(data[i * 15 + j + 1])
return color_, result_
if __name__ == '__main__':
color, result = read()
r = random.randint(0, 14)
c = random.randint(0, 14)
while result[r][c] != 0:
r = random.randint(0, 14)
c = random.randint(0, 14)
print(r, c)
C++随机下棋参考代码
#include <random>
#include <iostream>
using namespace std;
int chessboard[15][15];
int main() {
mt19937 mt(199793);
int color;
cin >> color;
for (auto &i : chessboard) {
for (int &j : i) {
cin >> j;
}
}
while (true) {
int r = mt() % 15;
int c = mt() % 15;
if (chessboard[r][c] == 0) {
cout << r << " " << c;
break;
}
}
return 0;
}
C语言随机下棋
#include <stdio.h>
#include <stdlib.h>
int chessboard[15][15];
int main()
{
int color;
scanf("%d", &color);
srand(199793);
for (int i = 0; i < 15; i++)
{
for (int j = 0; j < 15; j++)
{
scanf("%d", &chessboard[i][j]);
}
}
int r = rand() % 15, c = rand() % 15;
while (chessboard[r][c] != 0)
{
r = rand() % 15, c = rand() % 15;
}
printf("%d %d\n", r, c);
}