首页 > ACM题库 > HDU-杭电 > hdu 3214 Eclipse待解决[解题报告]C++
2014
03-07

hdu 3214 Eclipse待解决[解题报告]C++

Eclipse

问题描述 :

As you know, when the moon goes between you and the sun, it may block your sight, and thus you can only see part of the sun, or even cannot see it at all. This is called eclipse.
Now the news says that an eclipse will take place in several days. Being interested in astronomy, YY is curious whether he can observe the eclipse in the city he lives in, or he has to go somewhere else. Without loss of generality, YY models the problem as follows:
    1.There is one and only one light source, called ‘the sun’, in a 3-dimensional space. It is sphere shaped, centered at the origin (0, 0, 0), with radius R.
    2.There is one and only one obstacle, called ‘the moon’, in the same 3D space. It is also sphere shaped, center at the point (x0, y0, z0), with radius r. Besides, it is completely opaque.
    3.There is one and only one observer, called ‘YY’, in the same 3D space, too. He is not sphere shaped. Comparing to the moon and the sun, his volume is so small that he can be regarded as a point located at (x1, y1, z1).
    4.There is nothing and nobody else in the space.
    5.There is no assumption which of the two spheres is bigger.
    6.The sun and the moon neither intersect with each other, nor even touch. And for his safety and comfort, YY will not be inside or on the surface of any of the spheres.
Four situations may occur:
    1.Total eclipse: the sun is totally blocked by the moon, so no part of the sun can be seen by YY.
    2.Partial eclipse: part of the sun is blocked, and part can be seen. To be distinguished from annular eclipse, part of the border of the sun must be blocked in a partial eclipse.
    3.Annular eclipse: some central part of the sun is blocked and cannot be seen by YY, but the whole border of the sun must be visible.
    4.No eclipse at all: The whole sun is observable, so YY cannot observe any eclipse at all.

输入:

Input contains multiple test cases.

For each test case, there is only one single line consisting of 8 integers with absolute value no larger than 1000: R, r, x0, y0, z0, x1, y1, z1, indicating the radii of the sun and the moon, the location of the moon, and the location of YY. R and r are always positive.

A line with 8 space-separated 0s indicates the end of input.

输出:

Input contains multiple test cases.

For each test case, there is only one single line consisting of 8 integers with absolute value no larger than 1000: R, r, x0, y0, z0, x1, y1, z1, indicating the radii of the sun and the moon, the location of the moon, and the location of YY. R and r are always positive.

A line with 8 space-separated 0s indicates the end of input.

样例输入:

3 1 5 0 0 10 0 0
0 0 0 0 0 0 0 0

样例输出:

annular eclipse


  1. 第二个方法挺不错。NewHead代表新的头节点,通过递归找到最后一个节点之后,就把这个节点赋给NewHead,然后一直返回返回,中途这个值是没有变化的,一边返回一边把相应的指针方向颠倒,最后结束时返回新的头节点到主函数。

  2. 学算法中的数据结构学到一定程度会乐此不疲的,比如其中的2-3树,类似的红黑树,我甚至可以自己写个逻辑文件系统结构来。

  3. 我还有个问题想请教一下,就是感觉对于新手来说,递归理解起来有些困难,不知有没有什么好的方法或者什么好的建议?

  4. 第二块代码if(it != mp.end())应改为if(it != mp.end() && (i+1)!=(it->second +1));因为第二种解法如果数组有重复元素 就不正确