ACM.浙大1096.结果输入正确。但是提交不对。
悲剧了。
做了两道题。
都得上来问才明白。
都不是算法本身的问题。
对平台还是不了解。
大家给讲讲。
分不多呀。
题在这。
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1096
地铁。
一地到另一地时间。
d - the distance between stations, in metres
m - the maximum allowable speed of the train, in metres/sec
a - the maximum absolute acceleration of the train, in metres/sec2
j - the maximum absolute jerk, in metres/sec3
四个参数。
d两地距离。
m最大速度。
a最大加速度。
j加速度最大增加减少值。
求时间。
Sample Input
1000 70 20 1
Output for Sample Input
31.7
公式应该没问题。
用到二重积分。
下面是我的代码。
提交之后是Wrong Answer.
分不多。
大家帮帮忙。
估计以后还得麻烦大家。
分慢慢散。
- C/C++ code
///////////////////////////////////////////////////1096/////////////////////////////////////////////////////////////////#include <iostream>#include <iomanip>using namespace std;int main(){int d = 0, m = 0, a = 0, j = 0;double t1 =0, t2 = 0, t3 = 0, t = 0;double s1 = 0, s2 = 0;double v0 = 0; while(cin>>d>>m>>a>>j) { t1 = a/j; s1 = 0.8333333*(a*a + t*t*t); v0 = 0.25*(a*a + t1*t1); t2 = (m - v0)/a; s2 = v0*t + 0.5*a*t*t; t3 = (d - 2*(s1 + s2))/m; int temp1 = (t1+t2+t1+t2+t3)*10; double temp2 = temp1/10.0; cout<<setiosflags(ios::fixed); cout<<setprecision(1)<<temp2<<endl; } return 0;}[解决办法]
我的意思是你应该判断什么时间这个速度和加速度会达到输入的上限,求出来两个时间,然后根据这个时间分情况讨论吧
另外,你的速度表达式怎么来的?
[解决办法]
#include<iostream>
#include<cmath>
using namespace std;
double s,v,a,j,t1,t2,d;
double solve()
{
if (a*a>j*v)
{
t1=sqrt(v/j);
s=j*t1*t1*t1;
}
else
{
t1=a/j;
t2=v/j/t1-t1;
s=j*t1*t1*t1+1.5*j*t1*t1*t2+0.5*j*t1*t2*t2;
}
// printf("%lf %lf\n",t1,s);
if (2*s>d)
{
t1=pow(d/2/j,1.0/3.0);
// printf("%lf %lf\n",t1*j,a);
if (j*t1<a) return 4*t1;
else
{
t1=a/j;
t2=(-3*t1+sqrt(t1*t1+4*d/a))/2;
return 4*t1+2*t2;
}
}
else
{
if (a*a>j*v)
return 4*t1+(d-2*s)/v;
else return 4*t1+2*t2+(d-2*s)/v;
}
return 0;
}
int main()
{
while(scanf("%lf%lf%lf%lf",&d,&v,&a,&j)!=EOF)
{
printf("%0.1lf\n",solve());
}
return 0;
}
[解决办法]
边界值
[解决办法]
到我的资源下载里看看,里面资料丰富,包有你要的……