CF103C.Russian Roulette

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

After all the events in Orlando we all know, Sasha and Roma decided to find out who is still the team's biggest loser. Thankfully, Masha found somewhere a revolver with a rotating cylinder of n bullet slots able to contain exactly k bullets, now the boys have a chance to resolve the problem once and for all.

Sasha selects any k out of n slots he wishes and puts bullets there. Roma spins the cylinder so that every of n possible cylinder's shifts is equiprobable. Then the game starts, the players take turns, Sasha starts: he puts the gun to his head and shoots. If there was no bullet in front of the trigger, the cylinder shifts by one position and the weapon is given to Roma for make the same move. The game continues until someone is shot, the survivor is the winner.

Sasha does not want to lose, so he must choose slots for bullets in such a way as to minimize the probability of its own loss. Of all the possible variant he wants to select the lexicographically minimal one, where an empty slot is lexicographically less than a charged one.

More formally, the cylinder of n bullet slots able to contain k bullets can be represented as a string of n characters. Exactly k of them are "X" (charged slots) and the others are "." (uncharged slots).

Let us describe the process of a shot. Suppose that the trigger is in front of the first character of the string (the first slot). If a shot doesn't kill anyone and the cylinder shifts, then the string shifts left. So the first character becomes the last one, the second character becomes the first one, and so on. But the trigger doesn't move. It will be in front of the first character of the resulting string.

Among all the strings that give the minimal probability of loss, Sasha choose the lexicographically minimal one. According to this very string, he charges the gun. You have to help Sasha to charge the gun. For that, each x__i query must be answered: is there a bullet in the positions x__i?

在奥兰多发生的所有事件之后,我们都知道,萨沙和罗玛决定弄清楚谁仍是队里最大的“失败者”。幸运的是,玛莎不知从哪儿找到了一把左轮手枪,其转轮有 nn 个弹槽,恰好可容纳 kk 发子弹。现在,两个男孩终于有机会一劳永逸地解决这个问题了。

萨沙从 nn 个弹槽中任选 kk 个,并在其中装入子弹。罗玛随即旋转转轮,使得 nn 种可能的转轮位置(即 nn 种循环移位)出现的概率均等。接着游戏开始:双方轮流行动,萨沙先手——他将枪口对准自己头部并扣动扳机。若击发时击针正前方的弹槽为空,则转轮自动向前转动一格,武器交由罗玛执行相同操作。游戏持续进行,直至某人中弹;未中弹者获胜。

萨沙不想输,因此他必须以某种方式选择装填子弹的弹槽位置,使得自己输掉游戏的概率最小。在所有能达到该最小输概率的方案中,他希望选择字典序最小的一个,其中空槽(.)在字典序上小于实弹槽(X)。

更形式化地,一个容量为 kk 发子弹、共 nn 个弹槽的转轮可表示为一个长度为 nn 的字符串。其中恰好有 kk 个字符为 "X"(已装弹槽),其余为 "."(空槽)。

我们来描述一次射击的过程:假设击针正对字符串的第一个字符(即第一个弹槽)。若本次射击未造成伤亡且转轮发生位移,则字符串向左循环移位一次:原第一个字符变为最后一个字符,原第二个字符变为第一个字符,依此类推。但击针本身并不移动,它始终对准移位后字符串的第一个字符。

在所有能实现最小输概率的字符串中,萨沙选择字典序最小的那个,并据此装填手枪。你需要帮助萨沙完成装填。具体而言,对每个查询 xix_i,需回答:位置 xix_i 上是否有子弹?

输入格式

The first line contains three integers n, k and p (1 ≤ n ≤ 1018, 0 ≤ k ≤ n, 1 ≤ p ≤ 1000) — the number of slots in the cylinder, the number of bullets and the number of queries. Then follow p lines; they are the queries. Each line contains one integer x__i (1 ≤ x__i ≤ n) the number of slot to describe.

Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use cin, cout streams or the %I64d specificator.

第一行包含三个整数 nn、kk 和 pp(1 ≤ n ≤ 10181 \leq n \leq 10^{18},0 ≤ k ≤ n0 \leq k \leq n,1 ≤ p ≤ 10001 \leq p \leq 1000)——分别表示圆柱体中的槽数、子弹数以及查询次数。随后是 pp 行,即各次查询。每行包含一个整数 xix_i(1 ≤ xi ≤ n1 \leq x_i \leq n),表示待描述的槽的编号。

在 C++ 中,请勿使用 %lld 说明符读取或写入 64 位整数。推荐使用 cin、cout 流,或 %I64d 说明符。

输出格式

For each query print "." if the slot should be empty and "X" if the slot should be charged.

对于每个查询,如果该槽位应为空则输出“.”,如果该槽位应被填充则输出“X”。

输入输出样例

  • 输入#1

    3 1 3
    1
    2
    3

    输出#1

    ..X
  • 输入#2

    6 3 6
    1
    2
    3
    4
    5
    6

    输出#2

    .X.X.X
  • 输入#3

    5 2 5
    1
    2
    3
    4
    5

    输出#3

    ...XX

说明/提示

The lexicographical comparison of is performed by the < operator in modern programming languages. The a string is lexicographically less that the b string, if there exists such i (1 ≤ i ≤ n), that a__i < b__i, and for any j (1 ≤ j < i) a__j = b__j.

现代编程语言中,字典序比较由 < 运算符执行。若存在某个下标 ii(满足 1 ≤ i ≤ n1 ≤ i ≤ n),使得 ai < bia_i < b_i,且对任意 jj(满足 1 ≤ j < i1 ≤ j < i)都有 aj = bja_j = b_j,则称字符串 aa 字典序小于字符串 bb。

输入解题思路,AI测评打分。不知道怎么写?

首页