codeforces 976B (规律)

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 mgiven 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:


一、原题地址

    传送门


二、大致题意

    一个人在给定大小的地图里移动,一开始在(1,1)向下移动至(n,1)之后蛇形走位。最后到达(1,2)。现在给定移动的步数k,询问人现在所在的坐标。

三、思路

  模拟一下找到移动的规律。


四、代码
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
const int inf=0x3f3f3f3f;



int main()
{
	long long int n,m,k;
	scanf("%lld%lld%lld",&n,&m,&k);
	if(k<=n-1)
		printf("%lld 1\n",k+1);
	else 
	{
		long long int each=m-1;
		long long int now=k-n+1;
		long long int up=(now-1)/each;
		if(up&1)
		{
			printf("%lld %lld\n",n-up,m-(now-up*each)+1);
		}
		else
		{
			printf("%lld %lld\n",n-up,1+(now-up*each));
		}

	}
	getchar();
	getchar();
}
五、反思

  比赛的时候太着急,知道怎么推规律但是还是代码实现还是Wa了好多次。静下心仔细的想想,一下子就过掉了。以后的水题不能浮躁的写。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值