ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

寒假养成计划——Day6

2022-01-27 21:02:08  阅读:205  来源: 互联网

标签:养成 22 integer Day6 Sample int 寒假 Output Input


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 10^{-6}.


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 \sqrt{2}=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 10^{18} (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:本人实力较菜,只能做出这些简单题,后面的题如果有哪位大神可以解决可以私信我,如果这里面有讲的不清楚或者有错误的,望及时指出!

标签:养成,22,integer,Day6,Sample,int,寒假,Output,Input
来源: https://blog.csdn.net/weixin_50961321/article/details/122723060

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有