2014
11-29

# HeavenHelix

It’s said that MJ was invited to perform for the God. Unfortunately, God was intoxicated in the excellent voice and the moonwalk of MJ. The second day, God said, "Let there be MJ and there was MJ." So MJ stayed, leaving his poor fans’ hearts broken … (Sounds unrealistic.)
However, when the third day passed, MJ missed his Neverland so much. His soulful songs conveyed the sorrow to the God. So God built a new Neverland in the Heaven on the forth day. It is said that there is a Roller Coaster called HeavenHelix in the new Neverland. It is so huge that the train seemed to be just a point. The train does uniform circular motion on horizontal plane（The radius is r，and the angular speed is ω rad/s），while it does uniform liner motion in vertical direction（The speed is v m/s）from the top to the bottom. To monitor the train, there is a camera installed on the bottom, where the center of the circle is located. The amount of energy the camera consumes is up to the distance between the train and itself: Assuming the distance is D meters, and in the very moment it travels ds meters, the camera should consume X*D*ds kJ energy from the God. When the Neverland was built, God distributed E kJ energy to the camera initially. God had calculated accurately to make sure that the train will be exactly on the bottom, as soon as the energy is used up. MJ wanted to know how long he can enjoy himself riding the HeavenHelix the sky. Can you help him?

There are multiple cases. In each case, there will be only one line, containing five integers, r,ω, v, X and E (r≥0, ω≥0, v > 0, X > 0, E≥0), which have the same meaning mentioned above. All the numbers are smaller than 231. The input will be terminated by five zero, which were not need to be proceeded. There is a correct answer for each case.

There are multiple cases. In each case, there will be only one line, containing five integers, r,ω, v, X and E (r≥0, ω≥0, v > 0, X > 0, E≥0), which have the same meaning mentioned above. All the numbers are smaller than 231. The input will be terminated by five zero, which were not need to be proceeded. There is a correct answer for each case.

1 1 2 2 2
0 0 0 0 0

0.4062

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const double eps=1e-9;
#define Z(x) (fabs(x)<eps)
double r,w,v,X,E;
double f(double m)
{
if(Z(r))
{
return 0.5*X*v*v*m*m;
}
double ret=X*v*sqrt(r*r*w*w+v*v);
double sq=r*r/v/v;
double tmp=sqrt(m*m+sq);
double res=0.5*m*tmp+0.5*sq*log(m+tmp);
return ret*res;
}
int main()
{
while(scanf("%lf%lf%lf%lf%lf",&r,&w,&v,&X,&E))
{
if(Z(r)&&Z(w)&&Z(v)&&Z(X)&&Z(E))break;
double m,low=0.0,high=30.0*24.0*3600.0;
double f0=f(0.0);
int time=50;
while(time--)
{
m=(low+high)*0.5;
if(f(m)-f0>=E)high=m;
else low=m;
}
printf("%.4f\n",m+eps);
}
}

1. 为什么for循环找到的i一定是素数叻，而且约数定理说的是n=p1^a1*p2^a2*p3^a3*…*pk^ak，而你每次取余都用的是原来的m，也就是n

2. 在方法1里面：

//遍历所有的边，计算入度
for(int i=0; i<V; i++)
{
degree = 0;
for (j = adj .begin(); j != adj .end(); ++j)
{
degree[*j]++;
}
}

为什么每遍历一条链表，要首先将每个链表头的顶点的入度置为0呢？
比如顶点5，若在顶点1、2、3、4的链表中出现过顶点5，那么要增加顶点5的入度，但是在遍历顶点5的链表时，又将顶点5的入度置为0了，那之前的从顶点1234到顶点5的边不是都没了吗？