CF748A Santa Claus and a Place in a Class 题解
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 题解的更多相关文章
- codeforces 748E Santa Claus and Tangerines
E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Santa Claus and a Palindrome
Santa Claus and a Palindrome 题目链接:http://codeforces.com/contest/752/problem/D 贪心 很自然地,可以想到,若subS不是回文 ...
随机推荐
- lilypond进阶——用scheme修改乐谱细节
lilypond对乐谱内容的修改非常自由,用户可以自由根据需要做调整 调整一般都是用\override的命令,但是会比较冗长,码代码的时候比较麻烦 重新设置一个函数来概括命令,调用的时候使用的代码更短 ...
- Swift-技巧(八)CVPixelBuffer To CGImage
摘要 Swift 中图像的表现形式不只是 Image,还有更加底层的方式,比如 CVPixelBuffer 像素缓存形式,那么像素缓存转换为可以在应用中展示的 CGImage,就要知道有哪些处理了. ...
- Sentry 监控 - Snuba 数据中台架构(编写和测试 Snuba 查询)
系列 1 分钟快速使用 Docker 上手最新版 Sentry-CLI - 创建版本 快速使用 Docker 上手 Sentry-CLI - 30 秒上手 Source Maps Sentry For ...
- 【2020五校联考NOIP #8】狗
题面传送门 原题题号:Codeforces 883D 题意: 有 \(n\) 个位置,每个位置上要么有一条狗,要么有一根骨头,要么啥都没有. 现在你要给每个狗指定一个方向(朝左或朝右). 朝左的狗可以 ...
- R语言与医学统计图形-【18】ggplot2几何对象汇总
ggplot2绘图系统--几何对象汇总 前面介绍了常见的几种基本的几何对象,并且介绍了scale.stat等其他要素.后续将介绍position.themes.coord和faceting等函数. 这 ...
- centos安装后的个人工具
1.安装vim工具 yum -y install vim 安装完成后在家目录下新建一个.vimrc的配置文件.辅助vim软件功能. set number " 显示行号 set cursorl ...
- 笔记Mysql(1)
客户端的登录命令 查看版本 查看设置(数据库的基本设置信息) 查看时间 查看链接数 查看超时的关键字 创建数据库 查看已有数据库 进入数据库,查询链接到的数据库 查询数据目录 创建表 查看表
- IO流的字节输入输出流(InputStream,OutputStream)
字节输出流与文件字节输出流 文件存储原理和记事本打开文件原理 OutputStream及FileOutputStream import java.io.FileOutputStream; import ...
- 学习java的第十四天
一.今日收获 1.完成了手册第二章没有验证完成的例题 2.预习了第三章的算法以及for语句与if语句的用法 二.今日难题 1.验证上出现问题,没有那么仔细. 2.第二章还有没有完全理解的问题 三.明日 ...
- Leetcode中的SQL题目练习(二)
175. Combine Two Tables https://leetcode.com/problems/combine-two-tables/description/ Description Pe ...