问题

### Instructions: You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests. You will NOT return anything except for the program.
### Question:
There is a grid with H rows and W columns; initially, all cells are painted white. Let (i, j) denote the cell at the i-th row from the top and the j-th column from the left.
This grid is considered to be toroidal. That is, (i, 1) is to the right of (i, W) for each 1 \leq i \leq H, and (1, j) is below (H, j) for each 1 \leq j \leq W.
Takahashi is at (1, 1) and facing upwards. Print the color of each cell in the grid after Takahashi repeats the following operation N times.

- If the current cell is painted white, repaint it black, rotate 90^\circ clockwise, and move forward one cell in the direction he is facing. Otherwise, repaint the current cell white, rotate 90^\circ counterclockwise, and move forward one cell in the direction he is facing.

Input

The input is given from Standard Input in the following format:
H W N

Output

Print H lines. The i-th line should contain a string of length W where the j-th character is . if the cell (i, j) is painted white, and # if it is painted black.

Constraints


- 1 \leq H, W \leq 100
- 1 \leq N \leq 1000
- All input values are integers.

Sample Input 1

3 4 5

Sample Output 1

.#..
##..
....

The cells of the grid change as follows due to the operations:
.... #... ##.. ##.. ##.. .#..
.... → .... → .... → .#.. → ##.. → ##..
.... .... .... .... .... ....

Sample Input 2

2 2 1000

Sample Output 2

..
..

Sample Input 3

10 10 10

Sample Output 3

##........
##........
..........
..........
..........
..........
..........
..........
..........
#........#

### Format: Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within delimiters as follows.
```python
# YOUR CODE HERE
```

### Answer: (use the provided format with backticks)

答案

模型 模型答案 正确答案
金声玉亮2.0 ```python
import sys
input = sys.stdin.read
data = input().split()

H = int(data[0])
W = int(data[1])
N = int(data[2])

grid = [['.' for _ in range(W)] for _ in range(H)]

# Directions: 0: up, 1: right, 2: down, 3: left
directions = [(-1, 0), (0, 1), (1, 0), (0, -1)]
current_direction = 0
current_position = (0, 0)

for _ in range(N):
x, y = current_position
if grid[x][y] == '.':
grid[x][y] = '#'
current_direction = (current_direction + 1) % 4
else:
grid[x][y] = '.'
current_direction = (current_direction - 1) % 4

dx, dy = directions[current_direction]
current_position = ((x + dx) % H, (y + dy) % W)

for row in grid:
print(''.join(row))
```
[{"input": "3 4 5\n", "output": ".#..\n##..\n....\n", "testtype": "stdin"}, {"input": "2 2 1000\n", "output": "..\n..\n", "testtype": "stdin"}, {"input": "10 10 10\n", "output": "##........\n##........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n#........#\n", "testtype": "stdin"}]
deepseek-r1

```python
# YOUR CODE HERE
H, W, N = map(int, input().split())

grid = [[False for _ in range(W)] for _ in range(H)]
current_row, current_col = 0, 0
direction = 0 # 0: up, 1: right, 2: down, 3: left

for _ in range(N):
if grid[current_row][current_col]:
grid[current_row][current_col] = False
direction = (direction - 1) % 4
else:
grid[current_row][current_col] = True
direction = (direction + 1) % 4

if direction == 0:
current_row = (current_row - 1) % H
elif direction == 1:
current_col = (current_col + 1) % W
elif direction == 2:
current_row = (current_row + 1) % H
else:
current_col = (current_col - 1) % W

for row in grid:
print(''.join('#' if cell else '.' for cell in row))
```
[{"input": "3 4 5\n", "output": ".#..\n##..\n....\n", "testtype": "stdin"}, {"input": "2 2 1000\n", "output": "..\n..\n", "testtype": "stdin"}, {"input": "10 10 10\n", "output": "##........\n##........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n#........#\n", "testtype": "stdin"}]
gpto1 ```python
# YOUR CODE HERE
H, W, N = map(int, input().split())

grid = [[False]*W for _ in range(H)]

# Directions: Up, Right, Down, Left
directions = [(-1, 0), (0, 1), (1, 0), (0, -1)]
dir = 0 # Start facing up
x, y = 0, 0 # Starting position (0-indexed)

for _ in range(N):
if not grid[x][y]: # Current cell is white
grid[x][y] = True # Paint it black
dir = (dir + 1) % 4 # Rotate 90 degrees clockwise
else: # Current cell is black
grid[x][y] = False # Paint it white
dir = (dir - 1) % 4 # Rotate 90 degrees counterclockwise

dx, dy = directions[dir]
x = (x + dx) % H # Move to next cell (toroidal)
y = (y + dy) % W

# Output the grid
for row in grid:
line = ''.join('#' if cell else '.' for cell in row)
print(line)
```
[{"input": "3 4 5\n", "output": ".#..\n##..\n....\n", "testtype": "stdin"}, {"input": "2 2 1000\n", "output": "..\n..\n", "testtype": "stdin"}, {"input": "10 10 10\n", "output": "##........\n##........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n#........#\n", "testtype": "stdin"}]
gpt-4o-2024-08-06 ```python
# YOUR CODE HERE
def main():
import sys
input = sys.stdin.read
data = input().strip()
H, W, N = map(int, data.split())

# Initialize the grid with all white cells
grid = [['.' for _ in range(W)] for _ in range(H)]

# Directions: 0 = up, 1 = right, 2 = down, 3 = left
directions = [(-1, 0), (0, 1), (1, 0), (0, -1)]
direction = 0 # Start facing upwards

# Start position
x, y = 0, 0

for _ in range(N):
if grid[x][y] == '.':
# If white, paint black, turn right, move forward
grid[x][y] = '#'
direction = (direction + 1) % 4
else:
# If black, paint white, turn left, move forward
grid[x][y] = '.'
direction = (direction - 1) % 4

# Move forward in the current direction
dx, dy = directions[direction]
x = (x + dx) % H
y = (y + dy) % W

# Print the final grid
for row in grid:
print(''.join(row))

if __name__ == "__main__":
main()
```
[{"input": "3 4 5\n", "output": ".#..\n##..\n....\n", "testtype": "stdin"}, {"input": "2 2 1000\n", "output": "..\n..\n", "testtype": "stdin"}, {"input": "10 10 10\n", "output": "##........\n##........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n#........#\n", "testtype": "stdin"}]
DeepSeek-Coder-V2-Lite-Instruct ```python
# YOUR CODE HERE
def main():
import sys
input = sys.stdin.read
data = input().split()
H, W, N = int(data[0]), int(data[1]), int(data[2])

# Initialize the grid
grid = [['.' for _ in range(W)] for _ in range(H)]

# Directions: up, right, down, left
directions = [(-1, 0), (0, 1), (1, 0), (0, -1)]
direction_index = 0 # Start facing upwards

# Current position
x, y = 0, 0

for _ in range(N):
current_cell = grid[x][y]
if current_cell == '.':
# Repaint black and rotate clockwise
grid[x][y] = '#'
direction_index = (direction_index + 1) % 4
else:
# Repaint white and rotate counterclockwise
grid[x][y] = '.'
direction_index = (direction_index - 1) % 4

# Move forward in the current direction
dx, dy = directions[direction_index]
x = (x + dx) % H
y = (y + dy) % W

# Print the final grid
for row in grid:
print(''.join(row))

if __name__ == "__main__":
main()
```
[{"input": "3 4 5\n", "output": ".#..\n##..\n....\n", "testtype": "stdin"}, {"input": "2 2 1000\n", "output": "..\n..\n", "testtype": "stdin"}, {"input": "10 10 10\n", "output": "##........\n##........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n#........#\n", "testtype": "stdin"}]
Meta-Llama-3.1-405B-Instruct-Turbo ```python
import sys

H, W, N = map(int, sys.stdin.readline().split())

grid = [['.' for _ in range(W)] for _ in range(H)]

x, y = 0, 0
dx, dy = [-1, 0, 1, 0], [0, 1, 0, -1]
dir = 0

for _ in range(N):
if grid[x][y] == '.':
grid[x][y] = '#'
dir = (dir + 1) % 4
else:
grid[x][y] = '.'
dir = (dir - 1) % 4

x = (x + dx[dir]) % H
y = (y + dy[dir]) % W

for row in grid:
print(''.join(row))
```
[{"input": "3 4 5\n", "output": ".#..\n##..\n....\n", "testtype": "stdin"}, {"input": "2 2 1000\n", "output": "..\n..\n", "testtype": "stdin"}, {"input": "10 10 10\n", "output": "##........\n##........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n#........#\n", "testtype": "stdin"}]
Meta-Llama-3.1-70B-Instruct-Turbo ```python
import sys

H, W, N = map(int, sys.stdin.readline().split())

grid = [['.' for _ in range(W)] for _ in range(H)]

x, y = 0, 0
dx, dy = 0, 1

for _ in range(N):
if grid[x][y] == '.':
grid[x][y] = '#'
dx, dy = dy, -dx
else:
grid[x][y] = '.'
dx, dy = -dy, dx

x = (x + dx) % H
y = (y + dy) % W

for row in grid:
print(''.join(row))
```
[{"input": "3 4 5\n", "output": ".#..\n##..\n....\n", "testtype": "stdin"}, {"input": "2 2 1000\n", "output": "..\n..\n", "testtype": "stdin"}, {"input": "10 10 10\n", "output": "##........\n##........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n#........#\n", "testtype": "stdin"}]
Qwen2-72B-Instruct ```python
from collections import deque

def solve(H, W, N):
grid = [['.' for _ in range(W)] for _ in range(H)]
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] # Right, Down, Left, Up
direction = 3 # Start facing Up
x, y = 0, 0 # Start at (1, 1) but indexing is 0-based

for _ in range(N):
if grid[x][y] == '.':
grid[x][y] = '#'
direction = (direction + 1) % 4
else:
grid[x][y] = '.'
direction = (direction - 1) % 4

dx, dy = directions[direction]
x = (x + dx) % H
y = (y + dy) % W

for row in grid:
print(''.join(row))

H, W, N = map(int, input().split())
solve(H, W, N)
```

```
[{"input": "3 4 5\n", "output": ".#..\n##..\n....\n", "testtype": "stdin"}, {"input": "2 2 1000\n", "output": "..\n..\n", "testtype": "stdin"}, {"input": "10 10 10\n", "output": "##........\n##........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n#........#\n", "testtype": "stdin"}]
baichuan4 ```python
# YOUR CODE HERE
import sys

def print_grid(grid):
for row in grid:
print(''.join(row))

def simulate_movement(H, W, N):
# Initialize the grid with '.' representing white cells
grid = [['.' for _ in range(W)] for _ in range(H)]
# Directions: Up, Right, Down, Left
directions = [(-1, 0), (0, 1), (1, 0), (0, -1)]
# Start position and direction
x, y, d = 0, 0, 0 # x, y are 0-indexed

for _ in range(N):
if grid[x][y] == '.': # White cell
grid[x][y] = '#' # Paint black
d = (d + 1) % 4 # Rotate 90 degrees clockwise
else: # Black cell
grid[x][y] = '.' # Paint white
d = (d - 1) % 4 # Rotate 90 degrees counterclockwise
# Move forward
nx, ny = (x + directions[d][0]) % H, (y + directions[d][1]) % W
x, y = nx, ny

print_grid(grid)

# Read input from stdin
H, W, N = map(int, sys.stdin.readline().split())
simulate_movement(H, W, N)
```
```
[{"input": "3 4 5\n", "output": ".#..\n##..\n....\n", "testtype": "stdin"}, {"input": "2 2 1000\n", "output": "..\n..\n", "testtype": "stdin"}, {"input": "10 10 10\n", "output": "##........\n##........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n#........#\n", "testtype": "stdin"}]
doubao ```python
import numpy as np

H, W, N = map(int, input().split())

grid = np.full((H, W), '.')
direction = 0 # 0: up, 1: right, 2: down, 3: left
row = 0
col = 0

for _ in range(N):
if grid[row][col] == '.':
grid[row][col] = '#'
direction = (direction + 1) % 4
else:
grid[row][col] = '.'
direction = (direction - 1) % 4

if direction == 0:
row = (row - 1 + H) % H
elif direction == 1:
col = (col + 1) % W
elif direction == 2:
row = (row + 1) % H
elif direction == 3:
col = (col - 1 + W) % W

for i in range(H):
print(''.join(grid[i]))
```
[{"input": "3 4 5\n", "output": ".#..\n##..\n....\n", "testtype": "stdin"}, {"input": "2 2 1000\n", "output": "..\n..\n", "testtype": "stdin"}, {"input": "10 10 10\n", "output": "##........\n##........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n#........#\n", "testtype": "stdin"}]
gpto1 ```python
# YOUR CODE HERE
H, W, N = map(int, input().split())

grid = [[False]*W for _ in range(H)]

# Directions: Up, Right, Down, Left
directions = [(-1, 0), (0, 1), (1, 0), (0, -1)]
dir = 0 # Start facing up
x, y = 0, 0 # Starting position (0-indexed)

for _ in range(N):
if not grid[x][y]: # Current cell is white
grid[x][y] = True # Paint it black
dir = (dir + 1) % 4 # Rotate 90 degrees clockwise
else: # Current cell is black
grid[x][y] = False # Paint it white
dir = (dir - 1) % 4 # Rotate 90 degrees counterclockwise

dx, dy = directions[dir]
x = (x + dx) % H # Move to next cell (toroidal)
y = (y + dy) % W

# Output the grid
for row in grid:
line = ''.join('#' if cell else '.' for cell in row)
print(line)
```
[{"input": "3 4 5\n", "output": ".#..\n##..\n....\n", "testtype": "stdin"}, {"input": "2 2 1000\n", "output": "..\n..\n", "testtype": "stdin"}, {"input": "10 10 10\n", "output": "##........\n##........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n#........#\n", "testtype": "stdin"}]
kimi ```python
# YOUR CODE HERE
(H, W, N) = map(int, input().split())
grid = [['.' for _ in range(W)] for _ in range(H)]
dx = 0
dy = -1
x = 0
y = 0
for _ in range(N):
if grid[y][x] == '.':
grid[y][x] = '#'
dx = -dy
dy = dx
else:
grid[y][x] = '.'
dx = dy
dy = -dx
x = (x + dx) % W
y = (y + dy) % H
for row in grid:
print(''.join(row))
```
[{"input": "3 4 5\n", "output": ".#..\n##..\n....\n", "testtype": "stdin"}, {"input": "2 2 1000\n", "output": "..\n..\n", "testtype": "stdin"}, {"input": "10 10 10\n", "output": "##........\n##........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n#........#\n", "testtype": "stdin"}]
minimax ```python
# YOUR CODE HERE
from collections import deque

def rotate_clockwise(pos):
return (pos[1], -pos[0])

def rotate_counterclockwise(pos):
return (-pos[1], pos[0])

def move_forward(pos, direction):
return (pos[0] + direction[0], pos[1] + direction[1])

def get_opposite_direction(direction):
return (-direction[0], -direction[1])

def paint_grid(H, W, N):
grid = [['.' for _ in range(W)] for _ in range(H)]
pos = (0, 0)
direction = (0, -1) # facing upwards
for _ in range(N):
if grid[pos[0]][pos[1]] == '.':
grid[pos[0]][pos[1]] = '#'
direction = rotate_clockwise(direction)
else:
grid[pos[0]][pos[1]] = '.'
direction = rotate_counterclockwise(direction)
pos = move_forward(pos, direction)
# Toroidal grid handling
pos = (pos[0] % H, pos[1] % W)
return grid

def print_grid(grid
[{"input": "3 4 5\n", "output": ".#..\n##..\n....\n", "testtype": "stdin"}, {"input": "2 2 1000\n", "output": "..\n..\n", "testtype": "stdin"}, {"input": "10 10 10\n", "output": "##........\n##........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n#........#\n", "testtype": "stdin"}]
wenxinyiyan ```python
import sys

def get_next_position(cur_pos, cur_dir, H, W):
# Define the directions: 0=up, 1=right, 2=down, 3=left
dx = [0, 1, 0, -1]
dy = [-1, 0, 1, 0]

# Calculate the next position
x, y = cur_pos
nx, ny = (x + dx[cur_dir]) % H, (y + dy[cur_dir]) % W
if nx == 0: nx = H
if ny == 0: ny = W

return (nx, ny)

def get_next_direction(cur_dir, is_white):
# Rotate 90 degrees clockwise if white, counterclockwise if black
if is_white:
return (cur_dir + 1) % 4
else:
return (cur_dir - 1) % 4

def print_grid(grid, H, W):
for i in range(H):
for j in range(W):
print(grid[i][j], end='')
print()

# Read input values
H, W, N = map(int, sys.stdin.readline().split())

# Initialize the grid and Takahashi's position and direction
grid = [['.' for _ in range(W)] for _ in range(H)]
pos = (1, 1)
dir = 0 # 0: up, 1: right, 2: down, 3: left

# Perform N operations
for _ in range(N):
# Get the current cell color
is_white = grid[pos[0]-1][pos[1]-1] == '.'

# Repaint the cell and update the direction
grid[pos[0]-1][pos[1]-1] = '#' if is_white else '.'
dir = get_next_direction(dir, is_white)

# Move to the next position
pos = get_next_position(pos, dir, H, W)

# Print the final grid
print_grid(grid, H, W)
```
[{"input": "3 4 5\n", "output": ".#..\n##..\n....\n", "testtype": "stdin"}, {"input": "2 2 1000\n", "output": "..\n..\n", "testtype": "stdin"}, {"input": "10 10 10\n", "output": "##........\n##........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n#........#\n", "testtype": "stdin"}]
zhipu ```python
def main():
import sys
input = sys.stdin.read
data = input().split()
H, W, N = int(data[0]), int(data[1]), int(data[2])

# Initialize the grid with all cells white
grid = [['.' for _ in range(W)] for _ in range(H)]

# Directions correspond to [up, right, down, left]
directions = [(-1, 0), (0, 1), (1, 0), (0, -1)]
current_direction = 0 # Start facing up

# Starting position
x, y = 0, 0

for _ in range(N):
if grid[x][y] == '.':
grid[x][y] = '#'
current_direction = (current_direction + 1) % 4
else:
grid[x][y] = '.'
current_direction = (current_direction - 1) % 4

# Move forward in the current direction
dx, dy = directions[current_direction]
x = (x + dx) % H
y = (y + dy) % W

# Output the final grid
for row in grid:
print(''.join(row))

if __name__ == "__main__":
main()
```
[{"input": "3 4 5\n", "output": ".#..\n##..\n....\n", "testtype": "stdin"}, {"input": "2 2 1000\n", "output": "..\n..\n", "testtype": "stdin"}, {"input": "10 10 10\n", "output": "##........\n##........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n#........#\n", "testtype": "stdin"}]
deepseek-v3 ```python
# YOUR CODE HERE
H, W, N = map(int, input().split())

# Initialize the grid
grid = [[False for _ in range(W)] for _ in range(H)]

# Takahashi's initial position and direction
# Directions: 0 = up, 1 = right, 2 = down, 3 = left
x, y = 0, 0
direction = 0

# Define the movement deltas for each direction
delta = [(-1, 0), (0, 1), (1, 0), (0, -1)]

for _ in range(N):
# Check current cell color
if grid[x][y]:
# If black, repaint to white, rotate counterclockwise
grid[x][y] = False
direction = (direction - 1) % 4
else:
# If white, repaint to black, rotate clockwise
grid[x][y] = True
direction = (direction + 1) % 4

# Move forward
dx, dy = delta[direction]
x = (x + dx) % H
y = (y + dy) % W

# Print the grid
for row in grid:
line = ''.join(['#' if cell else '.' for cell in row])
print(line)
```
[{"input": "3 4 5\n", "output": ".#..\n##..\n....\n", "testtype": "stdin"}, {"input": "2 2 1000\n", "output": "..\n..\n", "testtype": "stdin"}, {"input": "10 10 10\n", "output": "##........\n##........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n#........#\n", "testtype": "stdin"}]