Content

圣诞老人坐在一个桌子被摆成 \(m\) 行 \(n\) 列的教室里。每个桌子有两个座位,每个位置从左往右都有编号,依次为 \(1,2,3,...,2\times n\times m\)。已知圣诞老人坐在编号为 \(k\) 的位置,求:

  • 圣诞老人坐在第几列第几行。
  • 圣诞老人的座位是在桌子的左边还是右边。

数据范围:\(1\leqslant n,m\leqslant 10000,1\leqslant k\leqslant 2\times 10^8\)(\(2\times n\times m\) 的最大值)。

Solution

首先,我们可以求出圣诞老人在第几列第几行。

我们不妨把一个桌子看成一个集体,然后这样编号:从第一列第一行开始,先从前往后,再从左往右,依次编号为 \(1,2,3,...,n\times m\)。那么,我们发现,圣诞老人此时的编号 \(s\) 就是 \(\left\lceil\dfrac{k}{2}\right\rceil\)。然后我们可以根据这个来求出列数和行数,分别是 \(\left\lceil\dfrac{s}{m}\right\rceil\),\(\begin{cases}m&m\mid s\\s\mod m&m\nmid s\end{cases}\)。

至于在左在右的问题,那就更简单了:如果 \(k\) 是奇数,那么就应该坐在桌子的左边,否则就应该坐在桌子的右边。

Code

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std; int n, m, k, mm, r, l; int main() {
scanf("%d%d%d", &n, &m, &k);
mm = (int)ceil(k / 2.0);
r = (int)ceil(mm * 1.0 / m), l = (mm % (m + 1) + 1);
printf("%d %d %c", r, l, (k % 2 ? 'L' : 'R'));
}

CF748A Santa Claus and a Place in a Class 题解的更多相关文章

  1. codeforces 748E Santa Claus and Tangerines

    E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  2. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) D. Santa Claus and a Palindrome STL

    D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...

  3. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E. Santa Claus and Tangerines

    E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  4. Codeforces Round #389 Div.2 E. Santa Claus and Tangerines

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  5. Codeforces Round #389 Div.2 D. Santa Claus and a Palindrome

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  6. Codeforces Round #389 Div.2 C. Santa Claus and Robot

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  7. Codeforces Round #389 Div.2 B. Santa Claus and Keyboard Check

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  8. Codeforces Round #389 Div.2 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 standa ...

  9. Santa Claus and a Palindrome

    Santa Claus and a Palindrome 题目链接:http://codeforces.com/contest/752/problem/D 贪心 很自然地,可以想到,若subS不是回文 ...

随机推荐

  1. [bzoj1109]堆积木

    用f[i]表示前i个数,i必须被贡献的答案,考虑转移,枚举下一个被贡献的数j,那么j需要满足:1.$j<i$:2.$a[j]<a[i]$:3.$a[i]-(i-j+1)\le a[j]$, ...

  2. 详解Python Streamlit框架,用于构建精美数据可视化web app,练习做个垃圾分类app

    今天详解一个 Python 库 Streamlit,它可以为机器学习和数据分析构建 web app.它的优势是入门容易.纯 Python 编码.开发效率高.UI精美. 上图是用 Streamlit 构 ...

  3. 多线程05.thread不知道的知识

    Thread thread = new Thread(); // init(null, null, "Thread-" + nextThreadNum(), 0); //init( ...

  4. Linux远程软件

    Xhell6:Linux的终端模拟软件 1>安装并破解:解压.破解(运行两个.bat文件).启动(点击Xshell.exe文件) 2>连接远端Linux系统: 创建会话:点击连接,在常规框 ...

  5. [LCT学习时的一些笔记]

    会找时间写一篇学习笔记的. \(Access\)的操作是把\(x\)和\(x\)所在原树的顶端点的路径变为一个\(splay\) 对于原树边我们有这样的操作,对每个\(splay\)的顶点维护一个父亲 ...

  6. Codeforces 702F - T-shirts(平衡树+势能分析)

    题面传送门 首先肯定将所有物品排个序. 考虑暴力做法,对于每个询问,枚举所有物品,能买就买.不过扫一眼就知道无法直接优化. 不妨换个角度,暴力做法是枚举询问,这次我们枚举物品.从左到右依次枚举所有物品 ...

  7. map与unordered_map区别及使用

    需要引入的头文件不同map: #include <map>unordered_map: #include <unordered_map> 内部实现机理不同map: map内部实 ...

  8. linux 线程函数小结

    由于主线程已经开始跑了,次线程还在使用串口打印需要一点时间,因此打印的都是重复的. #include "pthread.h" #include "stdio.h" ...

  9. phpexcel 另存Excel文件方式

    $w = new PHPExcel_Writer_Excel5($e); $dir = 'path/title.xls'; $w->save($dir);

  10. 添加页面、页面交互、动态添加页面tab

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="ViewDictTosPr ...