湖南大学第十六届程序设计竞赛(重现赛)题解
湖南大学第十六届程序设计竞赛(重现赛)题解
2021/7/15
A Triangles
链接:https://ac.nowcoder.com/acm/contest/18196/A
There are 3 kinds ofTriangles: acute triangles, right triangles and obtuse triangles.A triangle with an obtuse angle (the obtuse angle is greater than 90 degrees and less than 180 degrees) is an obtuse triangle (obviously only one angle can be obtuse angle). The three internal angles of a triangle are all acute angles (the acute angle is greater than zero and less than 90 degrees), which is called "acute triangle"; one internal angle is right angle (the right angle is equal to 90 degrees), which is called "right triangle".
Given the coordinates of three verticesof a triangle,write a program to judge the kind of the triangle. Note that three points may not form a triangle (for example, two or three vertices coincide, or three points are collinear).
输入描述:
1 | The first line contains one integerN(N ≤ 10,000), the number oftriangles. |
输出描述:
1 | OutputN lines. For each triangle, output one line.If the three points do not form a triangle, output "invalid"(Without quotation marks)If three points form an obtuse triangle, output "obtuse"(Without quotation marks)If three points form an acute triangle, output "acute"(Without quotation marks)If three points constitute a right triangle, output "right"(Without quotation marks) |
示例1
输入
1 | 4 |
输出
1 | acute |
题目大意
大概意思就是给定三个点的直角坐标,问你能不能构成三角形,如果能构成三角形则判断是锐角直角还是钝角三角形。
解题思路
先判断能不能构成三角形,由于在一个平面上,因此只要三点不共线、不共点,就一定能组成三角形。
-
先判断是否有共点,由于我们后面要用到三角形的边长,所以这里我们直接判断三条边是否都不等于 0 就行。设三边长 a b c ,即
-
再判断有没有三点共线,比较笨的方法就是求三条直线然后代入另外一个点坐标进去,判断是否在直线上。聪明一点就是判断是否有两个直线的斜率相同,即两条直线平行。
再判断是什么三角形:利用三角形的性质
代码
1 |
|
B Yuki with emofunc and playf
链接:https://ac.nowcoder.com/acm/contest/18196/B
题目描述
Today HNU is holding the hucpc2021, yuki is very excited and wants to attend this amazing contest. Unfortunately, the contest needs a team to participate, yuki can register a team only himself. However, yuki too weak and he does not want to compete with other teams only himself. Therefore poor yuki asks volunteers for help. After the volunteer's introduction, yuki knows two genius persons called emofunc and playf already registered a team, poor yuki finds them and tells them about his embarrassing situation. Emofunc and playf are generous and kind-hearted mans, they are so glad and decide to let yuki join their team. After 5 hours of exciting competition, there is no doubt that emofunc and playf win the champion in hucpc2021! Yuki is a really lucky dog because he has done nothing in the whole competition, poor yuki is so curious why emofunc and playf so strong and asks them for some life experiences. Emofunc and playf are very generous mans so they tell yuki a lot. After that, yuki knows emofunc and playf not only are very genius and study hard but also are magicians.
Yuki has an apple and there are participants in hucpc2021, he wants to share the apple to every participants, so he decides to divide the apple into pieces. But yuki is shocked after he knows the magic power of emofunc and playf. Playf's magic power can copy an item into ten and emofunc's magic power can copy an item into what number he wants, but emofunc lies to yuki and he says his magic power only can copy an item into x (emofunc always pretend he so weak). Yuki knows both the magic power of emofunc and playf then he decides not to divide the apple and he wants to bother emofunc and playf.
Yuki has two choices and assumes he has apple(s) now:
-
Bother playf. Give all the apples yuki has to playf, then playf uses his magic and returns 10∗k{10*k}10∗k apples to yuki, which is mean yuki has apples now.
-
Bother emofuc. Give an apple to emofuc, then emofunc uses his magic and returns x{x}x apples to yuki, which is mean yuki has apples now.
Yuki wants to minimize the total number of times of bother emofunc and playf, and let the total number of apples can be divided into N{N}N equal parts without split into pieces (image all apples are same), in other words, yuki has apples now and can be divided by . It is so difficult to yuki and yuki wants your help, can you tell the minimum number of total times to bother emofunc and playf to yuki?
输入描述:
1 | A line contains two integers N{N}N,x{x}x are mentioned in the description. |
输出描述:
1 | A line of an integer indicated the minimum number of total times to bother emofunc and playf, if there is no such way to satisfy yuki's require then output -1 |
示例1
输入
1 | 4 7 |
输出
1 | 2 |
示例2
输入
1 | 3 3 |
输出
1 | 1 |
示例3
输入
1 | 50 1 |
输出
1 | 2 |
示例4
输入
1 | 3 1 |
输出
1 | -1 |
题目大意
给出数字n和x,初始的k=1。可以进行以下两种操作
问最少操作多少次使得k是n的倍数,如果永远不能,则输出-1。
解题思路
让k是n的倍数,即满足,倒推一下得到两种操作
我们直接对问题进行bfs搜索最短操作数就行,范围是,起点为1,终点为0。
注意n=1时答案为0
代码
1 |
|
D Queuing
链接:https://ac.nowcoder.com/acm/contest/18196/D
There has already been a long line in front of the cafeteria before the school bell rang.
When the cafeteria opens, everyone in the queue rushes to one of the n windows in the cafeteria at a speed close to the speed of light, forming a new n queue.
This process follows the following rules:
-
Each person rushes to the window independently with a probability of ;
-
If A is in front of B at the beginning, and A and B rush to the same window, then A is still in front of B.
Playf is now ranked m in the team, which means that there are m-1 people ahead of Playf. Playf wants to know the expectation of rank of him in the new queue after the cafeteria opens.
输入描述:
1 | One line, two integers n and m. |
输出描述:
1 | One line, a floating point number, indicates the expectation of Playf' rank in the new queue. At least accurate to 1e-6. |
示例1
输入
1 | 2 3 |
输出
1 | 2.00000000 |
说明
There are 8 possibilities with equal probability
示例1
输入
1 | 2 4 |
输出
1 | 2.50000000 |
题目大意
给你n,m,n代表有n个窗口,m代表一开始前面有m-1个人,Playf排第m个。刚开始m个人全在第一个窗口,每个人有的概率去任意一个窗口,同时如果一开始A在B前面,A和B同时去一个窗口时,A还在B的前面。
问你换位后Playf在队伍中排位的期望。
解题思路
其实就是概率论的内容,可以看出来这是个二项分布,期望也就是np,这里的n是试验次数(除了Playf的人的个数),p是概率,对应关系为 :,由于求的是playf的排名期望,因此n对应的是playf前面的人的个数,所以此时除了playf的所有人的排名期望为,由于求的是playf的排名期望,加 1 即可(因为playf排在最后。
最后的公式为
代码
1 |
|
F Team
链接:https://ac.nowcoder.com/acm/contest/18196/F
题目描述
2021 HNU programing competition is coming. Everyone is very exciting and want to participate in the competition.
We all know that this competition is a team competition, with three people in one team.
Playf is a poor guy who is very weak in programing, He wants to participate in the competition although he is very stupid. Fortunately, he knew two genius persons called Yuki and Emo, and they are so warm-hearted to let playf join them.
Everyone has a programming ability value. The ability value of a team is the sum of the ability value of three people. Now we know the ability value of Yuki, Emo and Playf. Playf wants to know the ability value of his team. Can you tell him ?
输入描述:
1 | The first line contains an integer a indicating the programing ability value of Yuki |
输出描述:
1 | One integers indicating the ability value of Their team. |
示例1
输入
1 | 9223372036854775808 |
输出
1 | 18446744073709551616 |
题目大意
输入a,b,c求a+b+c
262<=a,b<=263,0<=c<=2
解题思路
高精度加法或
usigned long long表示范围是[0,264-1],而a+b+c的结果是[263,2^64+2]刚好超过3个数字,用unsigned long long存储后特判一下即可。(pow不能存2^64)
代码
1 |
|
G Binbin's string
链接:https://ac.nowcoder.com/acm/contest/18196/G
题目描述
One day, Binbin picked up a string S at the beach, but she likes string T. Therefore, she needs to take some action on the string to make the string S become the string T. She has two kind of operation to modify the string. The first operation is to delete Y characters after the X-th position of the string (including the X-th character).The second operation is to insert the string A after the X-th position of the string, if you want to insert it at the beginning, just insert A after the 0th position.
For example, there is a string S="iwannaac", choose the first operation, delete 2 characters after the 7th character, it will become "iwanna"; then choose the second operation, insert the string after the 6th character "wa", it will become "iwannawa".
How many operations does Binbin need to take at least to turn the string S into a string T ?
1≤∣S∣,∣T∣≤100000, |S| represents the length of the string S. |T| represents the length of the string T.
输入描述:
1 | The first line contains a string S consisting of lowercase letters. |
输出描述:
1 | Output a number, indicating the minimum number of operations required to turn the string into the target string |
示例1
输入
1 | binbindisliketowearskirts |
输出
1 | 1 |
示例2
输入
1 | binbinliketowearskirts |
输出
1 | 2 |
题目大意
给你两个字符串s1,s2 能对s1进行如下两种操作:
-
删除s1中连续的一段字符
-
在s1的某一位置添加一段字符
问最少操作多少次能把s1转换成s2
解题思路
有点有趣的题目hhh,思路就是,对于任意的字符串,最多操作两次就能把s1转换为s2,具体操作就是直接把s1删除后添加s2,也就是把整个s1替换成s2,两个操作。
因此我们只需要判断是否能通过一次删除或添加将s1变成s2。注意s1==s2的情况。
代码
1 |
|
I Binbin and Balls
链接:https://ac.nowcoder.com/acm/contest/18196/I
题目描述
Binbin gets a special material ball. As everyone knows, Binbin is a curious girl, so she decides to study the hardness of the ball. She finds a building with n storeys. Every time she chooses a floor f arbitrarily and throws a ball down from the f floor. The ball may be intact, but it may also be broken. If the ball is broken, it cannot be used again. Unfortunately, Binbin only has two balls, she wants to find the largest x that if she throws the ball down from the x floor, the ball will not be broken. Also, she wants to know in the worst case, how many times she needs to throw at least to find the value of x.
Note: It is certain that if a ball will be broken after dropped from x-th floor, it will also be broken after dropped from y-th floor where y>x.
输入描述:
1 | The first line contains an integer T (1<=T<=1e5)– the number of test cases. |
输出描述:
1 | Output T lines. Each line contains an integer – the minimum number of times Binbin needs to throw in the worst case. |
示例1
输入
1 | 2 |
输出
1 | 1 |
题目大意
给你两个相同的球,让你从n层楼中多次扔下去,求最差情况下找到让这个球从尽量高的层数扔下去不碎的层数的次数。
解题思路
设这个最少次数为 T ,则满足:在第T层扔下去时如果球碎掉,则这个层数在1~T-1之间,需要再扔T-1次,同理
如果没碎,就从T+T-1层往下扔,碎了就在T~2T-2之间······
推理得:最差情况下最多能保证得到1+2+3+4+·····+T楼的答案(全部包含),即层楼的答案,我们让这个式子大于等于n,即,化简后得到,因为,求得T的最小值为:
直接输出即可。
代码
1 |
|