题目描述:
You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy.
Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D environment. The dungeon can be represented as a rectangle matrix of n rows and m columns. Cell (x, y) is the cell in the x-th row in the y-th column. Lara can move between the neighbouring by side cells in all four directions.
Moreover, she has even chosen the path for herself to avoid all the traps. She enters the dungeon in cell (1, 1), that is top left corner of the matrix. Then she goes down all the way to cell (n, 1) — the bottom left corner. Then she starts moving in the snake fashion — all the way to the right, one cell up, then to the left to the cell in 2-nd column, one cell up. She moves until she runs out of non-visited cells. n and m given are such that she always end up in cell (1, 2).
Lara has already moved to a neighbouring cell k times. Can you determine her current position?
输入描述:
The only line contains three integers n, m and k (2 ≤ n, m ≤ 109, n is always even, 0 ≤ k < n·m). Note that k doesn’t fit into 32-bit integer type!
输出描述:
Print the cell (the row and the column where the cell is situated) where Lara ends up after she moves k times.
输入:
4 3 0
4 3 11
4 3 7
输出:
1 1
1 2
3 2
题意:
给定一个大小为 n*m 的地图,初始坐标为(1,1), 移动方式如图所示(在步数足够的情况下先向下走到头,再向右走到头,向上一格, 向左走到头,向上一格,向右走到头,然后往复循环,每个格子只能走一次。请你输出走k步后的坐标。
题解:
找规律
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
ll n,m,k;
while(scanf("%lld%lld%lld",&n,&m,&k)!=EOF){
if(k < n) printf("%lld 1\n",k+1);
else{
k -= n;
ll x = k / (m - 1);
printf("%lld ",n - x);
if(x & 1) printf("%lld\n",m - k % (m - 1));
else printf("%lld\n",k % (m - 1) + 2);
}
}
return 0;
}