2022.02.16翻译Beads

Beads
题目(https://acs.jxnu.edu.cn/problem/CF8E)描述:
One Martian boy called Zorg wants to present a string of beads to his friend from the Earth — Masha. He knows that Masha likes two colours: blue and red, — and right in the shop where he has come, there is a variety of adornments with beads of these two colours. All the strings of beads have a small fastener, and if one unfastens it, one might notice that all the strings of beads in the shop are of the same length. Because of the peculiarities of the Martian eyesight, if Zorg sees one blue-and-red string of beads first, and then the other with red beads instead of blue ones, and blue — instead of red, he regards these two strings of beads as identical. In other words, Zorg regards as identical not only those strings of beads that can be derived from each other by the string turnover, but as well those that can be derived from each other by a mutual replacement of colours and/or by the string turnover.

It is known that all Martians are very orderly, and if a Martian sees some amount of objects, he tries to put them in good order. Zorg thinks that a red bead is smaller than a blue one. Let's put 0 for a red bead, and 1 — for a blue one. From two strings the Martian puts earlier the string with a red bead in the i-th position, providing that the second string has a blue bead in the i-th position, and the first two beads i - 1 are identical.

At first Zorg unfastens all the strings of beads, and puts them into small heaps so, that in each heap strings are identical, in his opinion. Then he sorts out the heaps and chooses the minimum string in each heap, in his opinion. He gives the unnecassary strings back to the shop assistant and says he doesn't need them any more. Then Zorg sorts out the remaining strings of beads and buys the string with index k.

All these manupulations will take Zorg a lot of time, that's why he asks you to help and find the string of beads for Masha.

输入:
The input file contains two integers n and k (2 ≤ n ≤ 50;1 ≤ k ≤ 1016) —the length of a string of beads, and the index of the string, chosen by Zorg.

输出:
Output the k-th string of beads, putting 0 for a red bead, and 1 — for a blue one. If it s impossible to find the required string, output the only number -1.

样例输入:
4 4
样例输出:
0101
注释:
Let's consider the example of strings of length 4 — 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001, 1010, 1011, 1100, 1101, 1110. Zorg will divide them into heaps: {0001, 0111, 1000, 1110}, {0010, 0100, 1011, 1101}, {0011, 1100}, {0101, 1010}, {0110, 1001}. Then he will choose the minimum strings of beads in each heap: 0001, 0010, 0011, 0101, 0110. The forth string — 0101.

翻译:
一个火星人叫佐格想送一串珍珠给他的地球朋友玛莎。他知道玛莎喜欢两种颜色蓝色和红色,他已经去过右边商店了,哪里有多种多样带着这两种颜色的珍珠的装饰品。所有的珍珠链都有相同的扣件,并且如果一个未扣紧,他就会注意到商店里所有的珍珠链都是一样长的。因为火星人眼睛的特点,如果佐格一开始看到一个蓝红的珍珠链,然后其他的红色的而不是蓝色的珍珠链,和蓝色的而不是红色的珍珠链,他会认为这两种珍珠链是一样的。换句话说,佐格会认为那些可以通过旋转互相得到的珍珠链是一样的、那些可以通过颜色互换或旋转得到的珍珠链是一样的。

已知所有的火星人都非常讲究,如果佐格看到一些物品,他会尝试把他们按顺序排好。佐格认为红色的比蓝色的小。我们定义0为红色的珍珠,1为蓝色珍珠。对于两串珍珠链,火星人把第一串的红色珍珠防再第i个位置,把第二串的蓝色珍珠放在第i个位置,两串的第i-1个位置是一样的。

一开始佐格展开所有的珍珠链,把它们放在小堆里,把一样的珍珠链放成一堆。然后他整理这些堆,选择他认为每堆里最小的珍珠链。他把珍珠链还给店员并说他再也不需要它们了。然后佐格整理剩下的珍珠链,并且买了下标为k的珍珠链。

所有的这些整理将会花佐格大量的时间,他请你寻求帮助找到这串送给玛莎的珍珠链。

输入:
输入两个整数n和k(2 ≤ n ≤ 50;1 ≤ k ≤ 10的16次方) 表示一串珍珠链的长度和佐格为玛莎选的珍珠链的下标。

输出:
输出下标为k的珍珠链,0表示红珍珠,1表示蓝珍珠。如果不可能找到需要的珍珠链,输出一个数字-1。
样例输入:
4 4
样例输出:
0101
注释:
让我们考虑长度为4(样例1)的珍珠串:0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001, 1010, 1011, 1100, 1101, 1110。佐格将会把他们分成这些堆{0001, 0111, 1000, 1110}, {0010, 0100, 1011, 1101}, {0011, 1100}, {0101, 1010}, {0110, 1001}。然后他将会在每堆中选择出一个最小的珍珠串0001, 0010, 0011, 0101, 0110。下标为4的珍珠串0101就是答案。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值