A. Setting up Camp
题目描述
The organizing committee plans to take the participants of the Olympiad on a hike after the tour. Currently, the number of tents needed to be taken is being calculated. It is known that each tent can accommodate up to 333 people.
Among the participants, there are aaa introverts, bbb extroverts, and ccc universals:
- Each introvert wants to live in a tent alone. Thus, a tent with an introvert must contain exactly one person — only the introvert himself.
- Each extrovert wants to live in a tent with two others. Thus, the tent with an extrovert must contain exactly three people.
- Each universal is fine with any option (living alone, with one other person, or with two others).
The organizing committee respects the wishes of each participant very much, so they want to fulfill all of them.
Tell us the minimum number of tents needed to be taken so that all participants can be accommodated according to their preferences. If it is impossible to accommodate the participants in a way that fulfills all the wishes, output −1-1−1.
Input
Each test consists of multiple test cases. The first line contains a single integer ttt (1≤t≤1041 \le t \le 10^41≤t≤104) — the number of test cases. This is followed by the descriptions of the test cases.
Each test case is described by a single line containing three integers aaa, bbb, ccc (0≤a,b,c≤1090 \le a, b, c \le 10^90≤a,b,c≤109) — the number of introverts, extroverts, and universals, respectively.
Output
For each test case, output a single integer — the minimum number of tents, or −1-1−1 if it is impossible to accommodate the participants.
Example
10
1 2 3
1 4 1
1 4 2
1 1 1
1 3 2
19 7 18
0 0 0
7 0 0
0 24 0
1000000000 1000000000 1000000000
3
-1
3
-1
3
28
0
7
8
1666666667
题目分析
这道题题目写起来很长,但是想描述的内容很简单,就是三种类型的人去住帐篷,帐篷最多容纳3人。内向的人想一个人住一个帐篷,外向的人想住在三个人的帐篷里,普通人怎么住都可以,也就是任由学校分配。学校想要满足每一个人的需求,至少需要多少个帐篷。
那我们的方案可以选择为:内向的人一人一个帐篷,外向的人和外向的人住在一起,如果最后外向的人不够住满3人的话,用普通人补齐3人,普通人都分配为3人一个帐篷,可能有帐篷没住满3人,不过普通人不受限制。
参考代码
for _ in range(int(input())):
a, b, c = map(int, input().split())
cnt = a + (b+3-1) // 3
if b % 3 != 0:
c -= (b//3 + 1) * 3 - b
cnt += (c + 3 - 1)//3
if c < 0: print(-1)
else: print(cnt)
B. Fireworks
题目描述
One of the days of the hike coincided with a holiday, so in the evening at the camp, it was decided to arrange a festive fireworks display. For this purpose, the organizers of the hike bought two installations for launching fireworks and a huge number of shells for launching.
Both installations are turned on simultaneously. The first installation launches fireworks every aaa minutes (i.e., after a,2⋅a,3⋅a,…a, 2 \cdot a, 3 \cdot a, \dotsa,2⋅a,3⋅a,… minutes after launch). The second installation launches fireworks every bbb minutes (i.e., after b,2⋅b,3⋅b,…b, 2 \cdot b, 3 \cdot b, \dotsb,2⋅b,3⋅b,… minutes after launch).
Each firework is visible in the sky for m+1m + 1m+1 minutes after launch, i.e., if a firework was launched after xxx minutes after the installations were turned on, it will be visible every minute from xxx to x+mx + mx+m, inclusive. If one firework was launched mmm minutes after another, both fireworks will be visible for one minute.
What is the maximum number of fireworks that could be seen in the sky at the same time?
Input
Each test consists of several test cases. The first line contains a single integer ttt (1≤t≤1041 \le t \le 10^41≤t≤104) — the number of test cases. Then follow the descriptions of the test cases.
The first and only line of each test case contains integers aaa, bbb, mmm (1≤a,b,m≤10181 \le a, b, m \le 10^{18}1≤a,b,m≤1018) — the frequency of launching for the first installation, the second installation, and the time the firework is visible in the sky.
Output
For each set of input data, output a single number — the maximum number of fireworks that can be seen simultaneously.
Example
6
6 7 4
3 4 10
7 8 56
5 6 78123459896
1 1 1
1 1 1000000000000000000
2
7
17
28645268630
4
2000000000000000002
题目分析
有两个烟花发生装置,分别隔不同的时间发射烟花,烟花在空中的停留时间都是一样的。题目就是要求我们求出在某一时刻内能看到最多的烟花次数。两个数之间一定有公倍数,也就是两个装置存在一个时刻同时发射烟花,我们再求出在第一发烟花发射到熄灭之间又有多少烟花被发射,在第一个烟花熄灭的那个时刻,我们看到的烟花数最多。
参考代码
t = int(input())
for _ in range(t):
a, b, m = map(int, input().split())
ans = m//a + m//b + 2
print(ans)
C. Left and Right Houses
题目描述
In the village of Letovo, there are nnn houses. The villagers decided to build a big road that will divide the village into left and right sides. Each resident wants to live on either the right or the left side of the street, which is described as a sequence a1,a2,…,ana_1, a_2, \dots, a_na1,a2,…,a