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. LOJ 3066 - 「ROI 2016 Day2」快递(线段树合并+set 启发式合并)

    LOJ 题面传送门 人傻常数大,需要狠命卡--/wq/wq 画个图可以发现两条路径相交无非以下两种情况(其中红色部分为两路径的重叠部分,粉色.绿色的部分分别表示两条路径): 考虑如何计算它们的贡献,对 ...

  2. Topcoder 15405 - PrettyLiar(可删除背包+前缀和优化 dp)

    题面传送门 题意: 给出两个长度为 \(n\) 的数组 \(a,b\) 和一个整数 \(s\). 你可以任意重排数组 \(a,b\),总共 \((n!)^2\) 种方案. 现在又两个人 A,B 来玩游 ...

  3. 【豆科基因组】绿豆Mungbean, Vigna radiata基因组2014NC

    目录 来源 一.简介 二.结果 基因组组装 重复序列和转座子 基因组特征和基因注释 绿豆的驯化 豆科基因组复制历史 基于转录组分析的豇豆属形成 绿豆育种基因组资源 三.讨论 四.方法 材料 组装 SN ...

  4. LearnPython_week3

    函数说明 1 # -*- coding:utf-8 -*- 2 # Author:Wong Du 3 4 5 ###函数, 6 # 能避免代码重复, 7 # 方便代码修改等操作 8 def wong( ...

  5. 9. Delete Node in a Linked List

    Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...

  6. go channel 概述 - 管道

    概述 unix/linux OS 的一个进程的输出可以是另一个进程的输入,这些进程使用stdin与stdout设备作为通道,在进程之间传递数据. 同样的,GO中有io.Reader与io.Writer ...

  7. mysql之对象创建

    1 --创建表空间 2 create tablespace tablespace_name 3 innodb and ndb: 4 add datafile 'file_name' 5 innodb ...

  8. node.js require() 源码解读

    时至今日,Node.js 的模块仓库 npmjs.com ,已经存放了15万个模块,其中绝大部分都是 CommonJS 格式.这种格式的核心就是 require 语句,模块通过它加载.学习 Node. ...

  9. elasticSearch索引库查询的相关方法

    package com.hope.es;import org.elasticsearch.action.search.SearchResponse;import org.elasticsearch.c ...

  10. 使用jsp制作index,可以通过<c:if test==“管理员”>或<c:if test=="客户">来区别展示用户界面

    <%@ page contentType="text/html;charset=UTF-8" language="java" %><%@ ta ...