牛客 —— 湖南大学第十六届程序设计竞赛(重现赛)

A Triangles

题目描述
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).

输入描述:
The first line contains one integerN(N ≤ 10,000), the number oftriangles.
The following N lines, each line contains six integersin the following format:x1 y1 x2 y2 x3 y3Where ( x i , y i x_i,y_i xi,yi) i=1,2,3 arethe coordinates of three verticesof the triangle.
− 10 , 000 ≤ x i , y i ≤ 10 , 000 -10,000≤ x_i,y_i≤ 10,000 10,000xi,yi10,000,i=1,2,3

输出描述:
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

输入
4
0 0 2 0 1 2
0 0 0 1 1 0
0 0 1 0 -1 -1
0 0 1 0 2 0

输出
acute
right
obtuse
invalid

#include <bits/stdc++.h>
using namespace std;
int main() {
    int T;
    cin >> T;
    while (T--) {
        int X1, Y1, X2, Y2, X3, Y3;
        cin >> X1 >> Y1 >> X2 >> Y2 >> X3 >> Y3;
        if ((X2 - X1) * (Y3 - Y1) - (Y2 - Y1) * (X3 - X1) == 0)
            cout << "invalid" <<endl;
        else {
            int dis1 = (X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1);
            int dis2 = (X3 - X1) * (X3 - X1) + (Y3 - Y1) * (Y3 - Y1);
            int dis3 = (X2 - X3) * (X2 - X3) + (Y2 - Y3) * (Y2 - Y3);
            if (dis1 + dis2 == dis3 || dis2 + dis3 == dis1 || dis1 + dis3 == dis2)
                cout << "right" <<endl;
            else {
                if (dis1 + dis2 - dis3 < 0 || dis2 + dis3 - dis1 < 0 || dis1 + dis3 - dis2 < 0)
                    cout << "obtuse" <<endl;
                else 
                    cout << "acute" <<endl;
            }
        }
    }
    return 0;
}

B Yuki with emofunc and playf

题目描述
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 {N}N participants in hucpc2021, he wants to share the apple to every participants, so he decides to divide the apple into {N}N 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 {k}k apple(s) now:

  1. Bother playf. Give all the apples yuki has to playf, then playf uses his magic and returns {10k}10∗k apples to yuki, which is mean yuki has {10k}10∗k apples now.

  2. Bother emofuc. Give an apple to emofuc, then emofunc uses his magic and returns {x}x apples to yuki, which is mean yuki has {x-1+k}x−1+k 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 equal parts without split into pieces (image all apples are same), in other words, yuki has {k}k apples now and {k}k can be divided by {N}N. 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?

输入描述:
A line contains two integers N , x {N},{x} N,x are mentioned in the description.

1 ≤ N ≤ 1000000 , 1 ≤ x ≤ 1000000000 1\le N \le 1000000, 1 \le x \le 1000000000 1N1000000,1x1000000000

输出描述:
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
输出
2

示例2
输入
3 3
输出
1

示例3
输入
50 1
输出
2

示例4
输入
3 1
输出
-1
思路分析
根据题意,就是进行下面两个操作任选一个进行 k = k + 10 ) k=k+10) k=k+10) k = k + x − 1 k=k+x-1 k=k+x1
涉及到倍数问题,考虑在过程中进行模运算,可以转换为 k = ( k + 10 ) % n k=(k+10) \% n k=(k+10)%n k = ( k + x − 1 ) % n k=(k+x-1) \% n k=(k+x1)%n
之后和《抓住那头牛》这道题目很相似,直接BFS就可以了

D Queuing

题目描述
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:

  1. Each person rushes to the ith ( 1 ≤ i ≤ n 1\leq i\leq n 1in) window independently with a probability of 1/n;
  2. 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.

输入描述:
One line, two integers n and m.
1 < = n , m < = 1 e 9 1<=n,m<=1e9 1<=n,m<=1e9

输出描述:
One line, a floating point number, indicates the expectation of Playf’ rank in the new queue. At least accurate to 1e-6.

示例1
输入
2 3
输出
2.00000000
说明
There are 8 possibilities with equal probability
在这里插入图片描述

示例2
输入
2 4
输出
2.50000000

思路分析
偷懒一下,借用一下大神们的解释
在这里插入图片描述

#include <iostream>
using namespace std;
double n, m;
int main() {
    cin >> n >> m;
    printf("%.8lf", (m - 1) / n + 1);
    return 0;
}

F Team

题目描述
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 ?
输入描述:
The first line contains an integer a indicating the programing ability value of Yuki

The second line contains an integer b indicating the programing ability value of Emo

The third line contains an integer c indicating the programing ability value of Playf

2 62 ≤ a , b ≤ 2 63 , 0 ≤ c ≤ 22 2^{62}\le a,b\le2^{63}, 0\le c\le 22 262a,b263,0c22

输出描述:
One integers indicating the ability value of Their team.

示例1
输入
9223372036854775808
9223372036854775808
0
输出
18446744073709551616

思路分析
实际就是3个大整数相加,用Python来写

a = int(input())
b = int(input())
c = int(input())
print(a+b+c)

G Binbin’s string

题目描述
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. 1\le |S|,|T| \le 100000. 1S,T100000.
|S| represents the length of the string S.
|T| represents the length of the string T.

输入描述:
The first line contains a string S consisting of lowercase letters.

The second line contains a string T consisting of lowercase letters.

输出描述:
Output a number, indicating the minimum number of operations required to turn the string into the target string

示例1

输入
binbindisliketowearskirts
binbinliketowearskirts
输出
1

示例2

输入
binbinliketowearskirts
binbinliketowearlolita
输出
2

思路分析

操作次数只会出现一下三种情况:

  • 0:S和T相等
  • 1:将 S S S仅执行一次增添或删除即可得到 T T T
  • 2:全删1次,再增添上1次, 2次解决。
#include <bits/stdc++.h>
using namespace std;

bool f(string a, string b) {
    int j = 0;
    for (int i = 0; i < a.length(); i++) 
        if (a[i] == b[j])
            j++;
    return j == b.length();
}

int main(){
    string a, b;
    cin >> a >> b;
    if (a == b)
        puts("0");
    else if (f(a, b) || f(b, a))
        puts("1");
    else
        puts("2");
}

I Binbin and Balls

题目描述
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.

输入描述:
The first line contains an integer T (1<=T<=1e5)– the number of test cases.
In the next T lines, each line contains an integer n (1<=n<=1e18) – the number of storeys of the building.
输出描述:
Output T lines. Each line contains an integer – the minimum number of times Binbin needs to throw in the worst case.

示例1

输入
2
1
5

输出
1
3

思路分析
直接利用二分查找的思想就可以,复杂度 O ( n l o g n ) O(nlogn) O(nlogn)

#include<iostream>
#include<queue>
using namespace std;
#define ll long long 
ll n;
int main(){
    int T;
	cin>>T;
	while(T--){
		cin>>n;
		ll ans=0;
		ll l=0,r=2e9;
		while(l+1<r)
		{
			ll mid=(l+r)>>1;
			if(((mid+1)*mid)/2<=n)
			l=mid;
			else
			r=mid;
		}
		if((l+1)*l/2==n) 
		cout<<l<<endl;
		else
			cout<<l+1<<endl;
	}
    return 0;
}
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值