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不是回文 ...
随机推荐
- Atcoder Grand Contest 002 F - Leftmost Ball(dp)
Atcoder 题面传送门 & 洛谷题面传送门 这道 Cu 的 AGC F 竟然被我自己想出来了!!!((( 首先考虑什么样的序列会被统计入答案.稍微手玩几组数据即可发现,一个颜色序列 \(c ...
- #pragma warning(disable:4996)
VS使用中常常会遇到一些过时或者不安全的函数,编译会报错: 错误 C4996 'sscanf': This function or variable may be unsafe. Consider u ...
- DTOJ 4027:挖煤
挖煤 [问题描述]众所周知, 小C是挖煤好手.今天他带着他的魔法镐子去挖煤 ,他的镐子一开始有$w$点魔力.他的挖煤 路线 上会依次 经过$n$个地点, 地点, 每个 地点是煤矿或者补给站,设小C当前 ...
- fastq文件基本信息统计工具
之前写的一个小工具,写的很简陋,名字取的也很随意就叫skr,哈哈.主要是fq转fa.合并多个染色体的vcf文件等,功能不多(主要是C写起来太操蛋了T_T),通常我也只用来统计fastq文件信息: 这里 ...
- mongodb数据库简单类
<?php/*** Mongodb类** examples: * $mongo = new HMongodb("127.0.0.1:11223"); * $mongo-> ...
- 简单的Mybatis程序
1.新建一个普通Maven项目,导入 mybatis.mysql.junit(用于测试)3个依赖 Mybatis <dependency> <groupId>org.mybat ...
- linux vi和vim编辑器
所有的Linux系统都会内建vi文本编辑器,vim具有程序编辑的能力,可以看作是vi的增强版本 三种常见模式 正常模式 以vim打开一个文档直接进入的模式,快捷键可以使用. 1.这个模式可以使用上下左 ...
- MySQL8.0配置文件详解
mysql8.0配置文件一.关键配置1. 配置文件的位置 MySQL配置文件 /etc/my.cnf 或者 /etc/my.cnf.d/server.cnf几个关键的文件:.pid文件,记录了进程id ...
- Applescript快速入门及OmniFocus每日md报告开发
本篇主要记录 Applescript 基础语法,以及利用 applescript 生成 omnifocus 每日报告 从 windows 转换到 macos,最近一直在不断折腾,这两天浏览 githu ...
- [web安全] 利用pearcmd.php从LFI到getshell
有一段时间没写blog了,主要是事多,加上学的有些迷茫,所以内耗比较大.害,沉下心好好学吧. 漏洞利用背景: 允许文件包含,但session等各种文件包含都已经被过滤了.ctf题中可以关注regist ...