这些代码片段之间有什么区别?
What are the differences between these code snippets?
我正在尝试解决来自 LightOJ 的 this 问题。我编写了以下代码,但它的答案判断有误。
#include <bits/stdc++.h>
using namespace std;
int main()
{
int tc;
scanf("%d",&tc);
int dum = 0;
while(tc--)
{
double a,b;
scanf("%Lf : %Lf",&a,&b);
double theta = atan(b/a);
double med = a + theta * sqrt(a*a + b*b);
double rat = 200.0000f/(med);
printf("Case %d: %.8Lf %.8Lf\n",++dum,a*rat,b*rat);
}
return 0;
}
但以下类似的被接受了。
#include <stdio.h>
#include <math.h>
const double PI=acos(-1.0);
int main ()
{
int T,a,b;
scanf("%d",&T);
for (int cas=1;cas<=T;cas++)
{
scanf("%d : %d",&a,&b);
double alpha=atan(1.0*a/b);
double R=200.0/(2.0*sin(alpha)+(PI-2*alpha));
printf("Case %d: %.8lf %.8lf\n",cas,2*R*sin(alpha),2*R*cos(alpha));
}
return 0;
}
我的解决方案哪里做错了?
程序描述:我正在接受 2 个输入 a 和 b.Where a/b = l/w(l = 长度,w= 宽度)。然后我计算角度 theta .并且,然后我得到了 arc 和 arc + l = 200 的公式。我得到了比例。
下一行中 %Lf
的使用不正确。
double a,b;
scanf("%Lf : %Lf",&a,&b);
%Lf
适合 long double
,而不适合 double
。使用 %lf
.
我正在尝试解决来自 LightOJ 的 this 问题。我编写了以下代码,但它的答案判断有误。
#include <bits/stdc++.h>
using namespace std;
int main()
{
int tc;
scanf("%d",&tc);
int dum = 0;
while(tc--)
{
double a,b;
scanf("%Lf : %Lf",&a,&b);
double theta = atan(b/a);
double med = a + theta * sqrt(a*a + b*b);
double rat = 200.0000f/(med);
printf("Case %d: %.8Lf %.8Lf\n",++dum,a*rat,b*rat);
}
return 0;
}
但以下类似的被接受了。
#include <stdio.h>
#include <math.h>
const double PI=acos(-1.0);
int main ()
{
int T,a,b;
scanf("%d",&T);
for (int cas=1;cas<=T;cas++)
{
scanf("%d : %d",&a,&b);
double alpha=atan(1.0*a/b);
double R=200.0/(2.0*sin(alpha)+(PI-2*alpha));
printf("Case %d: %.8lf %.8lf\n",cas,2*R*sin(alpha),2*R*cos(alpha));
}
return 0;
}
我的解决方案哪里做错了?
程序描述:我正在接受 2 个输入 a 和 b.Where a/b = l/w(l = 长度,w= 宽度)。然后我计算角度 theta .并且,然后我得到了 arc 和 arc + l = 200 的公式。我得到了比例。
下一行中 %Lf
的使用不正确。
double a,b;
scanf("%Lf : %Lf",&a,&b);
%Lf
适合 long double
,而不适合 double
。使用 %lf
.