C题大赛-A-E
wflengxuenong · · 个人记录
A:
Doremy's Perfect Math Class
题面翻译
给定一个正整数集合
- 从集合中选两个数
x 和y ,使得x 和y 满足x>y 并且x-y 不在集合S 中。 - 将
x-y 作为一个新元素加入到集合中。
假设操作方式是最优的,输出到无法操作时集合
题目描述
"Everybody! Doremy's Perfect Math Class is about to start! Come and do your best if you want to have as much IQ as me!" In today's math class, Doremy is teaching everyone subtraction. Now she gives you a quiz to prove that you are paying attention in class.
You are given a set
- choose two integers
x andy from the setS such thatx > y andx - y is not in the setS . - add
x-y into the setS .
You need to tell Doremy the maximum possible number of integers in
输入格式
The input consists of multiple test cases. The first line contains a single integer
The first line contains an integer
The second line contains
It is guaranteed that the sum of
输出格式
For each test case, you need to output the maximum possible number of integers in
样例 #1
样例输入 #1
2
2
1 2
3
5 10 25
样例输出 #1
2
5
提示
In the first test case, no such
In the second test case,
After performing all operations, the number of integers in
B:
Prime Square
题面翻译
定义一个
- 所有的数不大于
10^5 - 所有的数不是质数
- 每行、每列的和都是质数
输入
翻译 by jun头吉吉
题目描述
Sasha likes investigating different math objects, for example, magic squares. But Sasha understands that magic squares have already been studied by hundreds of people, so he sees no sense of studying them further. Instead, he invented his own type of square — a prime square.
A square of size
- all numbers on the square are non-negative integers not exceeding
10^5 ; - there are no prime numbers in the square;
- sums of integers in each row and each column are prime numbers.
Sasha has an integer
输入格式
The first line contains a single integer
Each of the next
输出格式
For each test case print
样例 #1
样例输入 #1
2
4
2
样例输出 #1
4 6 8 1
4 9 9 9
4 10 10 65
1 4 4 4
1 1
1 1
C:
Numbers on Whiteboard
题面翻译
题目描述
Numbers
You should perform the given operation
For example, if
- choose
a = 4 andb = 2 , so the new number is3 , and the whiteboard contains[1, 3, 3] ; - choose
a = 3 andb = 3 , so the new number is3 , and the whiteboard contains[1, 3] ; - choose
a = 1 andb = 3 , so the new number is2 , and the whiteboard contains[2] .
It's easy to see that after
输入格式
The first line contains one integer
The only line of each test case contains one integer
It's guaranteed that the total sum of
输出格式
For each test case, in the first line, print the minimum possible number left on the board after
样例 #1
样例输入 #1
1
4
样例输出 #1
2
2 4
3 3
3 1
D:
Paint the Array
题面翻译
给出一个指令序列L,R,U,D 四个大写字母组成
若机器人当前坐标为
- 如果当前字母为
L,那么机器人就会向左移动到x-1,y - 如果当前字母为
R,那么机器人就会向右移动到x+1,y - 如果当前字母为
U,那么机器人就会向上移动到x,y+1 - 如果当前字母为
D,那么机器人就会向下移动到x,y-1
如果一个坐标的点被走过了两次(除
一个操作序列合法,当且仅当中途机器人不会爆炸,并且满足指令序列结束时,机器人的坐标为
当然,空指令序列也是合法的
我们发现,所有的指令序列不一定都合法
给出一个指令序列
输入格式
第一行一个整数
接下来
输出格式
对于每组数据:
第一行一个整数,表示最多剩下多少条指令,使得指令序列合法,如果无论如何都不合法,输出
第二行表示合法的指令序列,如果有多个合法序列,输出任意一个
如果无论如何都不合法,输出空的一行(注意那一行要空出来,详情见样例)
数据范围
其中
感谢 @_Wolverine 提供的翻译
题目描述
Recently you have bought a snow walking robot and brought it home. Suppose your home is a cell
You also have the sequence of instructions of this robot. It is written as the string
- If the current instruction is 'L', then the robot can move to the left to
(x - 1, y) ; - if the current instruction is 'R', then the robot can move to the right to
(x + 1, y) ; - if the current instruction is 'U', then the robot can move to the top to
(x, y + 1) ; - if the current instruction is 'D', then the robot can move to the bottom to
(x, y - 1) .
You've noticed the warning on the last page of the manual: if the robot visits some cell (except
So the sequence of instructions is valid if the robot starts in the cell
The initial sequence of instructions, however, might be not valid. You don't want your robot to break so you decided to reprogram it in the following way: you will remove some (possibly, all or none) instructions from the initial sequence of instructions, then rearrange the remaining instructions as you wish and turn on your robot to move.
Your task is to remove as few instructions from the initial sequence as possible and rearrange the remaining ones so that the sequence is valid. Report the valid sequence of the maximum length you can obtain.
Note that you can choose any order of remaining instructions (you don't need to minimize the number of swaps or any other similar metric).
You have to answer
输入格式
The first line of the input contains one integer
The next
It is guaranteed that the sum of
输出格式
For each test case print the answer on it. In the first line print the maximum number of remaining instructions. In the second line print the valid sequence of remaining instructions
样例 #1
样例输入 #1
6
LRU
DURLDRUDRULRDURDDL
LRUDDLRUDRUL
LLLLRRRR
URDUR
LLL
样例输出 #1
2
LR
14
RUURDDDDLLLUUR
12
ULDDDRRRUULL
2
LR
2
UD
0
提示
There are only two possible answers in the first test case: "LR" and "RL".
The picture corresponding to the second test case:
Note that the direction of traverse does not matter Another correct answer to the third test case: "URDDLLLUURDR".