lzagddsg @ 2022-08-07 17:53:41
我的代码:
#include <bits/stdc++.h>
using namespace std;
int x[3], y[3], dis[3];
double ans;
int main()
{
cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2];
dis[0] = sqrt((x[1] - x[0]) * (x[1] - x[0]) + (y[1] - y[0]) * (y[1] - y[0]));
dis[1] = sqrt((x[2] - x[1]) * (x[2] - x[1]) + (y[2] - y[1]) * (y[2] - y[1]));
dis[2] = sqrt((x[0] - x[2]) * (x[0] - x[2]) + (y[0] - y[2]) * (y[0] - y[2]));
ans = 1.00 * (dis[0] + dis[1] + dis[2]);
printf("%.2lf", ans);
return 0;
}
在样例测试的时候明显是
by lzagddsg @ 2022-08-07 18:01:23
补:后来我想了想是不是没用到函数的问题,改了下代码
#include <bits/stdc++.h>
using namespace std;
int x[3], y[3], dis[3];
double ans;
double distance(int a, int b, int c, int d, int e, int f)
{
dis[0] = sqrt((x[1] - x[0]) * (x[1] - x[0]) + (y[1] - y[0]) * (y[1] - y[0]));
dis[1] = sqrt((x[2] - x[1]) * (x[2] - x[1]) + (y[2] - y[1]) * (y[2] - y[1]));
dis[2] = sqrt((x[0] - x[2]) * (x[0] - x[2]) + (y[0] - y[2]) * (y[0] - y[2]));
ans = 1.00 * (dis[0] + dis[1] + dis[2]);
return ans;
}
int main()
{
cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2];
printf("%.2f", distance(x[0], y[0], x[1], y[1], x[2], y[2]));
return 0;
}
然后放入评测机测试,还是
by Always_Remember_It @ 2022-08-07 18:02:27
@lzagddsg x,y,dis是double
by lzagddsg @ 2022-08-07 18:03:48
@zswmb 好的,我试试。
by hanzhang666 @ 2022-08-07 18:04:20
x,y,dis是double类型。 改后代码:
#include <bits/stdc++.h>
using namespace std;
double x[3], y[3], dis[3];
double ans;
double distance(int a, int b, int c, int d, int e, int f)
{
dis[0] = sqrt((x[1] - x[0]) * (x[1] - x[0]) + (y[1] - y[0]) * (y[1] - y[0]));
dis[1] = sqrt((x[2] - x[1]) * (x[2] - x[1]) + (y[2] - y[1]) * (y[2] - y[1]));
dis[2] = sqrt((x[0] - x[2]) * (x[0] - x[2]) + (y[0] - y[2]) * (y[0] - y[2]));
ans = 1.00 * (dis[0] + dis[1] + dis[2]);
return ans;
}
int main()
{
cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2];
printf("%.2f", distance(x[0], y[0], x[1], y[1], x[2], y[2]));
return 0;
}
by lzagddsg @ 2022-08-07 18:04:49
@zswmb 谢谢,