CF585C.Alice, Bob, Oranges and Apples
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Alice and Bob decided to eat some fruit. In the kitchen they found a large bag of oranges and apples. Alice immediately took an orange for herself, Bob took an apple. To make the process of sharing the remaining fruit more fun, the friends decided to play a game. They put multiple cards and on each one they wrote a letter, either 'A', or the letter 'B'. Then they began to remove the cards one by one from left to right, every time they removed a card with the letter 'A', Alice gave Bob all the fruits she had at that moment and took out of the bag as many apples and as many oranges as she had before. Thus the number of oranges and apples Alice had, did not change. If the card had written letter 'B', then Bob did the same, that is, he gave Alice all the fruit that he had, and took from the bag the same set of fruit. After the last card way removed, all the fruit in the bag were over.
You know how many oranges and apples was in the bag at first. Your task is to find any sequence of cards that Alice and Bob could have played with.
爱丽丝和鲍勃决定吃一些水果。他们在厨房里发现了一大袋橙子和苹果。爱丽丝立刻为自己拿了一个橙子,鲍勃则拿了一个苹果。为了使分享剩余水果的过程更有趣,两人决定玩一个游戏:他们准备了多张卡片,每张卡片上写着一个字母,要么是 'A',要么是 'B'。接着,他们从左到右依次移除卡片;每次移除一张标有 'A' 的卡片时,爱丽丝就将她当时拥有的所有水果全部交给鲍勃,并从袋中取出与她此前所拥有的苹果数量相同、橙子数量也相同的水果(即苹果数和橙子数均保持不变)。若移除的卡片上写的是 'B',则鲍勃执行相同操作:将其当时拥有的所有水果全部交给爱丽丝,并从袋中取出与他此前所拥有的苹果数量相同、橙子数量也相同的水果。当最后一张卡片被移除后,袋中的水果恰好全部取完。
已知最初袋中橙子和苹果的数量。你的任务是找出任意一个爱丽丝和鲍勃可能使用的卡片序列。
输入格式
The first line of the input contains two integers, x, y (1 ≤ x, y ≤ 1018, xy > 1) — the number of oranges and apples that were initially in the bag.
输入的第一行包含两个整数 x 和 y(1≤x,y≤1018,且 xy>1)—— 分别表示袋子中最初所含的橙子和苹果的数量。
输出格式
Print any sequence of cards that would meet the problem conditions as a compressed string of characters 'A' and 'B. That means that you need to replace the segments of identical consecutive characters by the number of repetitions of the characters and the actual character. For example, string AAABAABBB should be replaced by string 3A1B2A3B, but cannot be replaced by 2A1A1B2A3B or by 3AB2A3B. See the samples for clarifications of the output format. The string that you print should consist of at most 106 characters. It is guaranteed that if the answer exists, its compressed representation exists, consisting of at most 106 characters. If there are several possible answers, you are allowed to print any of them.
If the sequence of cards that meet the problem statement does not not exist, print a single word Impossible.
输出任意一个满足题目条件的卡牌序列,将其表示为仅包含字符 'A' 和 'B' 的压缩字符串。也就是说,你需要将连续相同字符组成的段替换为该字符的重复次数后跟该字符本身。例如,字符串 AAABAABBB 应被替换为 3A1B2A3B,而不能替换为 2A1A1B2A3B 或 3AB2A3B。请参考样例以进一步明确输出格式。你输出的字符串长度至多为 106 个字符。题目保证:若答案存在,则其压缩表示也一定存在,且长度至多为 106 个字符。若存在多个可能的答案,输出其中任意一个即可。
若不存在满足题面要求的卡牌序列,则输出单个单词 Impossible。
输入输出样例
输入#1
1 4
输出#1
3B
输入#2
2 2
输出#2
Impossible
输入#3
3 2
输出#3
1A1B
说明/提示
In the first sample, if the row contained three cards with letter 'B', then Bob should give one apple to Alice three times. So, in the end of the game Alice has one orange and three apples, and Bob has one apple, in total it is one orange and four apples.
In second sample, there is no answer since one card is not enough for game to finish, and two cards will produce at least three apples or three oranges.
In the third sample, cards contain letters 'AB', so after removing the first card Bob has one orange and one apple, and after removal of second card Alice has two oranges and one apple. So, in total it is three oranges and two apples.
在第一个样例中,如果该行包含三张字母为 “B” 的卡片,则 Bob 应向 Alice 各给出一个苹果,共三次。因此,游戏结束时,Alice 拥有一个橙子和三个苹果,Bob 拥有一个苹果,总计为一个橙子和四个苹果。
在第二个样例中,不存在合法答案,因为仅有一张卡片不足以使游戏结束;而两张卡片则至少会产生三个苹果或三个橙子。
在第三个样例中,卡片上的字母为 “AB”,因此在移除第一张卡片后,Bob 拥有一个橙子和一个苹果;在移除第二张卡片后,Alice 拥有两个橙子和一个苹果。因此,总计为三个橙子和两个苹果。
输入解题思路,AI测评打分。不知道怎么写?