(A,D,F,G,I)
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).
输入描述:
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 (xi,yi) i=1,2,3 arethe coordinates of three verticesof the triangle.
-10,000≤ xi,yi ≤ 10,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)
这其实是一个简单的关于几何的题目,只要把每个三角形的角的cos算出来正负就行
首先算出三条直线的长度a,b,c.
运用此公式:cosA=(b*b+c*c-a*a)/(2*b*c)
cosA大于0是锐角,等于0是直角,小于0是钝角。
再判断是否在一条直线或重合即可
重合是a,b,c任一个等于0就行
同一条线有与坐标轴平行的还有斜线
斜线判断任两条线的斜度即可
(y1-y2)/(x1-x2)
这是代码
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;
int main()
{
int n;
int x1,y1,x2,y2,x3,y3;
cin>>n;
while (n--) {
cin>>x1>>y1>>x2>>y2>>x3>>y3;
int a,b,c;
int A,B,C;
int f;
a=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
b=(x1-x3)*(x1-x3)+(y1-y3)*(y1-y3);
c=(x2-x3)*(x2-x3)+(y2-y3)*(y2-y3);
double k1=((double)y1-y2)*1.0/((double)x1-x2)*1.0;
double k2=((double)y1-y3)*1.0/((double)x1-x3)*1.0;
double k3=((double)y2-y3)*1.0/((double)x2-x3)*1.0;
if(k1==k2 || k1==k3 || k2==k3) {
cout<<"invalid"<<endl;
continue;
}
if((x1==x2 && x2==x3) || (y1==y2 && y2==y3) || (y1==y2 && x1==x2) || (x1==x3 && y1==y3) || (x2==x3 && y2==y3)) {
f=0;
} else {
A=c+b-a;
B=c+a-b;
C=a+b-c;
if(A>0 && B>0 && C>0) {
f=1;
} else {
if(A==0||B==0||C==0) {
f=2;
} else {
if(A<0 || B<0 || C<0) {
f=3;
}
}
}
}
if(f==0) {
cout<<"invalid"<<endl;
} else {
if(f==1) {
cout<<"acute"<<endl;
} else {
if(f==2) {
cout<<"right"<<endl;
} else {
if(f==3) {
cout<<"obtuse"<<endl;
}
}
}
}
}
return 0;
}
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:
1. Each person rushes to the ith (1≤i≤n1\leq i\leq n1≤i≤n) 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<=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
一道简单(bushi)的规律题。
规律就是(m-1)/n+1。
#include <stdio.h>
int main()
{
long long n,m;
scanf("%lld %lld",&n,&m);
double f;
f=((double)m-1)/(double)n+1.0;
printf("%.8lf\n",f);
return 0;
}
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 ?
输入描述:
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 262≤a,b≤263,0≤c≤22^{62}\le a,b\le2^{63}, 0\le c\le 2262≤a,b≤263,0≤c≤2
输出描述:
One integers indicating the ability value of Their team.
示例1
输入
9223372036854775808 9223372036854775808 0
输出
18446744073709551616
一道字符串的计算题
细节是结果字符串的长度预估
可以先行预估
从前两段字符串的尾部开始加(最后一个是小于2的数字,第一次就可以加上,后面就不用管了)
再用另一个数字储存进位的数字即可
详情看代码就行了
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;
int main()
{
char s1[1003],s2[1003];
int x;
cin>>s1;
cin>>s2;
cin>>x;
int i,j,k,p,q;
int len1=strlen(s1);
int len2=strlen(s2);
int len;
char s[1003];
if(s1[0]-48+s2[0]-48>=10) {
len=max(len1,len2)+1;
} else {
len=max(len1,len2);
}
q=0;
for (j=len-1,i=len1-1,k=len2-1; j>=0; j--,i--,k--) {
if(j==len-1) {
p=s1[i]-48+s2[k]-48+x;
} else {
p=s1[i]-48+s2[k]-48+q;
}
if(i<0) {
p+=48;
}
if(k<0) {
p+=48;
}
if(p>=10) {
s[j]=p%10+48;
q=p/10;
} else {
s[j]=p+48;
q=0;
}
}
cout<<s<<endl;
return 0;
}
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.1\le |S|,|T| \le 100000.1≤∣S∣,∣T∣≤100000.
|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
我觉得是一道字符串找规律题
其实这题只需要搞清楚需要多少次就行
最多也就两次
因为你也可以把A全删掉然后再加上T【dog】
首先判断是否一样,S==T就直接输出0就行
然后分别从头尾开始有多少是相同的
当从头开始数的数(g)大于等于S字符串从尾部数的数(r)时,则S字符串中少了,加上一段即可
当g大于等于T从尾部数的数(l)时,则S中多了,减去一段即可
以上两种情况都是一次
其他情况则都是两次
代码如下:
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
string s,t;
cin>>s;
cin>>t;
int g=0;
int r=s.size()-1;
int l=t.size()-1;
while (s[g]==t[g]) {
g++;
}
while (s[r]==t[l]) {
r--;
l--;
}
if(s==t) {
cout<<"0"<<endl;
} else {
if(g>=r || g>=l) {
cout<<"1"<<endl;
} else {
cout<<"2"<<endl;
}
}
return 0;
}
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.
输入描述:
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
用二分法就行
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
int t;
long long n;
cin>>t;
while(t--) {
cin>>n;
long long l=0,r=2e9;
while (l<r) {
long long mid=(l+r)/2;
if(mid*(mid+1)/2<n) {
l=mid+1;
} else {
r=mid;
}
}
cout<<l<<endl;
}
return 0;
}