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不是回文 ...
随机推荐
- [SQL Server]一列多行转换为字符串
在 SQL Server 中,如何将多行数据变成一个字符串保存. skill 投石 挖矿 刮痧 上面三行数据想要得到结果为:投石,挖矿,刮痧 有两种方式: 拼接字符串. 使用 for XML 首先创建 ...
- Atcoder Regular Contest 117 D - Miracle Tree(分析性质+构造)
Atcoder 题面传送门 笑死,阴间语文作业到现在还没写完,为了在这个点保持精神,我只好来颓篇题解辣 我们考虑探究一下怎么最小化 \(\max\limits_{i=1}^nE_i\),我们假设 \( ...
- C/C++内存几大分区和存储空间的布局
先看一下可执行文件加载进内存后形成的进程在内存中的结构,如下图: 代码区:存放CPU执行的机器指令,代码区是可共享,并且是只读的. 数据区:存放已初始化的全局变量.静态变量(全局和局部).常量数据. ...
- MAC——解决问题:打不开,因为它来自身份不明的开发者
今天在mac电脑上,下载了一个软件,是从某个网页上下载的,点击却不能打开,弹出窗口提示说"打不开xx,因为它来自身份不明的开发者",怎么解决?下面来看下. 方法/步骤 点击 ...
- 日常Java 2021/10/21
Java Iterator(迭代器) 如果需要使用iterator类需要从java.util包中引入它 Java Iterator不是一个集合,它是一种访问集合的方法,用于迭代ArrayList和Ha ...
- 大数据学习day36-----flume02--------1.avro source和kafka source 2. 拦截器(Interceptor) 3. channel详解 4 sink 5 slector(选择器)6 sink processor
1.avro source和kafka source 1.1 avro source avro source是通过监听一个网络端口来收数据,而且接受的数据必须是使用avro序列化框架序列化后的数据.a ...
- STM32 CAN用队列缓冲接收的例子
[1]CAN接收用队列缓冲的例子: 发单帧没有问题,多帧或者连续发两帧就有问题.
- 100个Shell脚本—【脚本6】拷贝目录
[脚本6]拷贝目录 编写shell脚本,把/root/目录下的所有目录(只需要一级)拷贝到/tmp/目录下: 一.脚本 #!/bin/bash cd /root list=(`ls`) for i i ...
- 【编程思想】【设计模式】【结构模式Structural】组合模式composite
Python版 https://github.com/faif/python-patterns/blob/master/structural/composite.py #!/usr/bin/env p ...
- 查看IP访问量的shell脚本汇总
第一部分,1,查看TCP连接状态 netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn netstat -n | awk '/^tcp/ {++S[ ...