976B Lara Croft and the New Game


B. Lara Croft and the New Game
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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?

Input

The only line contains three integers nm and k (2 ≤ n, m ≤ 109n is always even0 ≤ k < n·m). Note that k doesn't fit into 32-bit integer type!

Output

Print the cell (the row and the column where the cell is situated) where Lara ends up after she moves k times.

Examples
input
Copy
4 3 0
output
Copy
1 1
input
Copy
4 3 11
output
Copy
1 2
input
Copy
4 3 7
output
Copy
3 2
Note

Here is her path on matrix 4 by 3:


题意:一个n*m的举证,开始点在1,1这个位置,然后向下走,走到底向右走,然后在蛇形走,就是注释图的那种走法,然后走k步以后,输出当前走到的位置。


题解:先特判,k是不是小于n 的,表示走的步数只能在第一列。其余一定走出第一列了,k减去第一列的步数,就是剩下的(m-1)列的步数,用除和取余操作,如果剩下的x是奇数就输出n-x,m-y。否则就是n-x,y+2.这个规律 eg:2 2 2这组样例,比赛的时候没推出来,过了几天搜索博客看别人题解的。

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,m,k,x,y;
    cin>>n>>m>>k;
    if(k<n)
        cout<<k+1<<" "<<1;
    else
    {
        k-=n;
        x=k/(m-1);
        y=k%(m-1);
        if(x&1)
            cout<<n-x<<" "<<m-y;
        else cout<<n-x<<" "<<y+2;
    }
    return 0;
}


猜你喜欢

转载自blog.csdn.net/memory_qianxiao/article/details/80203901