Santa Claus and a Place in a Class (Codeforces-748A)

题目链接:

http://codeforces.com/problemset/problem/748/A

A. Santa Claus and a Place in a Class
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are n lanes of m desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to n from the left to the right, the desks in a lane are numbered from 1 to m starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture).

The organizers numbered all the working places from 1 to 2nm. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right.

The picture illustrates the first and the second samples.

Santa Clause knows that his place has number k. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right!

Input

The only line contains three integers nm and k (1 ≤ n, m ≤ 10 0001 ≤ k ≤ 2nm) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place.

Output

Print two integers: the number of lane r, the number of desk d, and a character s, which stands for the side of the desk Santa Claus. The character s should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right.

Examples
input
4 3 9
output
2 2 L
input
4 3 24
output
4 3 R
input
2 4 4
output
1 2 R

题目大意:

第一行输入n m k,n表示有n竖道桌子(两张桌子放一块),m表示有m排桌子,k表示该同学的桌子编号,要求计算该学生在第几竖道、在第几排、在左边还是在右边(左边输出‘L’,右边输出‘R’)桌子编号规则:如题目中的图示。

解题思路:

从该生所在位置开始算起,ansm存储排数,k依次减2,ansm++,直到到达第一排为止(需要提前标记第一排桌子编号,我运用了mapring器),计算出排数,列数利用公式:

k为奇数:

(该生所在列的第一排桌子编号 - 1)/(2*m)

k为偶数:

(发生所在列的第一排桌子编号 - 2)/(2*m)

代码:

#include<iostream>
#include<map>
using namespace std;
int main()
{
    int n,m,k;
    cin>>n>>m>>k;
    map<int,int>M;
    for(int i=0;;i=i+2)
    {
        if(i*m+1>2*n*m)   //根据n和m的取值范围,桌子最大编号为2*n*m
            break;
        M[i*m+1]=1;   //把每一竖排第一行的第一张桌子标记下来
        M[i*m+2]=1;   //把每一竖排第一行的第二张桌子标记下来
    }
    int ansm=1,s=k;   //ansm储存该学生在第几排
    while(1)   //计算该学生在第几排(从该生所在的排数开始减,知道第一排为止,ansm依次++)
    {
        if(M[s]==1)   //已经到达第一排,可以跳出循环了,ansm即为排数
            break;
        ansm++;
        s=s-2;   //因为两张桌子放一块的,所以每次减2
    }
    if(k%2==0)   //k为偶数,则一定在右边,再计算列数
        cout<<(s-2)/(2*m)+1<<' '<<ansm<<' '<<'R'<<endl;
    else   //k为奇数,则在左边,计算列数
        cout<<(s-1)/(2*m)+1<<' '<<ansm<<' '<<'L'<<endl;
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值