A题
Problem Statement
There are N points in a two-dimensional plane. The coordinates of the i-th point are (xi,yi).
Find the maximum length of a segment connecting two of these points.
Constraints
- 2≤N≤100
- −1000≤xi,yi≤1000
- (xi,yi) ≠ (xj,yj) (i ≠ j)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N x1 y1 x2 y2 ⋮ xN yN
Output
Print the maximum length of a segment connecting two of the points.
Your answer will be considered correct when the absolute or relative error from the judge's answer is at most .
Sample Input 1
3 0 0 0 1 1 1
Sample Output 1
1.4142135624
For the 1-st and 3-rd points, the length of the segment connecting them is =1.41421356237…, which is the maximum length.
Sample Input 2
5 315 271 -2 -621 -205 -511 -952 482 165 463
Sample Output 2
1455.7159750446
题解:
这道题数据量很小,暴力判断就行,注意答案的精度。
AC代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
int x[105],y[105];
memset(x,0,sizeof(x));
memset(y,0,sizeof(y));
for (int i=0;i<n;i++)
scanf("%d%d",&x[i],&y[i]);
double ans=0.0;
for (int i=0;i<n;i++)
{
for (int j=i+1;j<n;j++)
ans=max(ans,sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])));
}
printf("%.8lf\n",ans);
return 0;
}
B题
Problem Statement
Among the positive integers that consist of 0's and 2's when written in base 10, find the K-th smallest integer.
Constraints
- K is an integer between 1 and (inclusive).
Input
Input is given from Standard Input in the following format:
K
Output
Print the answer as an integer.
Here, the exact value must be printed as an integer, even if it is big. Exponential notations such as 2.34e+22
, for example, or unnecessary leading zeros such as 0523
are not allowed.
Sample Input 1
3
Sample Output 1
22
The positive integers that consist of 0's and 2's when written in base 10 are 2,20,22,… in ascending order.
The (K=) 3-rd of them, which is 22, should be printed.
Sample Input 2
11
Sample Output 2
2022
Sample Input 3
923423423420220108
Sample Output 3
220022020000202020002022022000002020002222002200002022002200
Note that the exact value of the answer must be printed as an integer, even if it is big.
题解:
看到最后一个样例,就知道最少应该拿string做(或者边处理边输出结果),实际上,把所有的‘2’变成‘1’之后,就是1~n的二进制表示法,所以这道题实际上就是要把K转换成二进制数,然后所有的‘1’输出为‘2’即可。
有两种普遍的写法:第一种是用递归方式写,好处是输出的顺序与答案是一样的;第二种是非递归的形式,本人采用第二种方式,用一个string容器存储每一步的结果,最后将这个字符串倒过来就是最后的答案了。
AC代码:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll k;
cin>>k;
string s;
while (k>0)
{
if (k%2==0)
s+="0";
else
s+="2";
k/=2;
}
reverse(s.begin(),s.end());
cout<<s<<endl;
return 0;
}
ps:本人实力较菜,只能做出这些简单题,后面的题如果有哪位大神可以解决可以私信我,如果这里面有讲的不清楚或者有错误的,望及时指出!