这些代码段之间有什么区别?

时间:2015-09-29 13:58:28

标签: c++ computational-geometry

我试图解决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。其中a / b = l / w(l =长度,w =宽度)。然后我计算角度theta。然后,我得到了弧的公式,并且弧为+ l = 200。我得到了这个比例。

1 个答案:

答案 0 :(得分:1)

在以下行中使用%Lf不正确。

double a,b;
scanf("%Lf : %Lf",&a,&b);

%Lf适用于long double,而非double。使用%lf

相关问题