1694A. Creep
้ก็ฎ
Define the score of some binary string ๐ as the absolute difference between the number of zeroes and ones in it. (for example, ๐= 010001 contains 4 zeroes and 2 ones, so the score of ๐ is $|4โ2|=2$).
Define the creepiness of some binary string ๐ as the maximum score among all of its prefixes (for example, the creepiness of ๐= 01001 is equal to 2 because the score of the prefix ๐[1โฆ4] is 2 and the rest of the prefixes have a score of 2 or less).
Given two integers ๐ and ๐, construct a binary string consisting of ๐ zeroes and ๐ ones with the minimum possible creepiness.
Input
The first line contains a single integer ๐ก (1โค๐กโค1000) ย โ the number of test cases. The description of the test cases follows.
The only line of each test case contains two integers ๐ and ๐ (1โค๐,๐โค100) ย โ the numbers of zeroes and ones correspondingly.
่ชชๆ
้้กๅฏไปฅ็ดๆฅๆๆธๅญธๅผๅๅบไพใ
- ๆๅฐๅผๆ่ณๅฐ(็ดๆฅ็ๆดๅๅญไธฒ)ๆฏ $|a - b|$๏ผๆไปฅๅฐฑ่จญๆณๆง้ ๅบ้ๆจฃ็ๆ ๆณใ
- ๅฏไปฅ็ดๆฅๆง้ min(a, b)*“01” + |a - b|*(a > b?‘0’:‘1’)
Code
|
|