周记(1)

前段时间参加了icpc网络赛的第一场,有两道题目题目还是有点说头的。

首先是F题(可以算是签到题)

题目如下

The role of Keqing, Yuheng of the Liyue Qixing, is to manage real estate and construction in Liyue.Today Keqing decides to leave her office and visit two places - Chasm, and Jueyun Karst - to make sure the building progress is at a reasonable pace.The location of Keqing’s office and the two places to visit can be denoted as three points on a 2D Cartesian coordinate system.

Keqing’s office, the start point, is located at point O (0, 0).
Chasm is located at point A (a, b).
Jueyun Karst is located at point B (2a, 0).

Keqing plans to visit Chasm first and then go to Jueyun Karst. Because Keqing is an experienced land overseer, she does not need to be at the exact location to do her job. She can finish the visit if the distance between her and the target point is no greater than R.
Please help Keqing find the shortest path to visiting Chasm and Jueyun Karst.

Input

There are T test cases in this problem.
The first line has one integer T.
In the following T lines, each contains three integers a, b, R.
We guarantee that 0 < a, b, R < 109, a^2 + b^2 > 4R^2, and 0 < T ≤ 1000.

Output

For each test case, you should first print “Case #t: ” (without quotes), where t is the index of this test case.
Then in the same line, print a number L, the length of the shortest path to finish the visit, rounded to two decimal places.

Example

standard input

1
3 5 1

standard output

Case #1: 9.00

Note
In the sample input, we have Chasm at (3,5), Jueyun Karst at (6,0), and Keqing can finish the visiting within radius 1.
So Keqing could go directly to point (3,4) first to visit Chasm, then reach (5.4,0.8) to visit Jueyun Chasm.
The total length is 5+4=9. We can prove that there is no path with a smaller distance.
----------------------------------------------------------------

这道题目相对简单

很多人可能去考虑这个最短距离到底是怎么算的,甚至在用高中的几何数学(因为我就是= =

但是由于是对称的,所以只需要代入样例中的公式即可(我自己设置了几个样例代入检测觉得公式没问题QAQ,至于为什么……我会继续想的...)

于是大家可能就得到了如下的代码:

#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
int main()
{
	ll T,t=0;
	cin>>T;
	while(t<T)
	{
		ll a,b,r;
		cin>>a>>b>>r;
		if(t+1==T)
		{
				double s=sqrt(a*a+(b-r)*(b-r));
				printf("Case #%d: %.2f",t+1,2*s-r);
			t++;
		}
		else
		{
				double s=sqrt(a*a+(b-r)*(b-r));
				printf("Case #%d: %.2f\n",t+1,2*s-r);
			t++;
		}
	}
}

运行之后当然是WA了……

但是有一个小情况可能值得考虑,就是b比r大

这个时候就不需要再去用公式了,直接从原点走到(2a,0)即可!

代码如下

#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
int main()
{
	ll T,t=0;
	cin>>T;
	while(t<T)
	{
		ll a,b,r;
		cin>>a>>b>>r;
		if(t+1==T)
		{
			if(b<=r) printf("Case #%d: %.2f",t+1,(2*a-r)*1.0);
			else
			{
				double s=sqrt(a*a+(b-r)*(b-r));
				printf("Case #%d: %.2f",t+1,2*s-r);
			}
			t++;
		}
		else
		{
			if(b<=r) printf("Case #%d: %.2f\n",t+1,(2*a-r)*1.0);
			else
			{
				double s=sqrt(a*a+(b-r)*(b-r));
				printf("Case #%d: %.2f\n",t+1,2*s-r);
			}
			t++;
		}
	}
}

另外一题就是I题,我个人认为是最简单的一题了……但是我写了好久都没写出来,甚至用了字符串……(真是有够无语的)

其实最终还是因为忘了怎么判别回车符……(好久没写过需要判别回车符的题+基础不牢靠的我终究还是吃了一个大亏)

ch=getchar();   牢记在心了铁汁们!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值