第四届吉林省大学生程序设计大赛个人解题报告 Problem B: The Farmer’s Heritage

来源:互联网 发布:做淘宝客服有什么前途 编辑:程序博客网 时间:2024/04/29 15:51

Problem B: The Farmer’s Heritage


A farmer who had worked hard all his life on his triangular farm was taken sick. He knew that he must soon die. He called his three sons about his bed to give them some advice. "My sons," said he, "keep all of the land which I leave you. Do not sell any of it, for there is a treasure in the soil. I shall not tell you where to hunt for it, but if you try hard to find it, and do not give up, you will surely succeed. As soon as the harvest is over, begin your search with plow, and spade, and rake. Turn every foot of earth, and then turn it again and again. The treasure is there." After the father died, the sons gathered in the harvest. As soon as the grain had been cared for, they planned to search for the hidden treasure. The farm was divided into three small triangles. Each son agreed to dig carefully his part. Every foot of soil was turned by the plow or by the spade. It was next harrowed and raked, but no treasure was found. That seemed very strange. "Father was an honest man and a wise man," said the youngest son. "He would never have told us to hunt for the treasure if it were not here. Do you not remember that he said, 'Turn the soil again and again'? He surely thought the treasure worth hunting for." "Our land is in such good condition now that we might as well sow winter wheat," said the oldest son. His brothers agreed to this and the wheat was sown. The next harvest was so great that it surprised them. No neighbor's field bore so many bushels of wheat to the acre. The sons were pleased with their success.   This story tells us that we must work hard to success. And do you know how these three sons divide the farm? Because of their ages, three sons acquired different are of this heritage. The eldest brother should get 1/2, the second should get 1/3, and the youngest son get 1/6.


Input
There are x and y coordinates of three triangle vertices in one line. These six
numbers are all real number. The edge against  the first vertex belongs to the eldest brother, the edge against the third vertex belongs to the youngest, and so the second. For each case, you should find a point inside the triangle that can divide the original triangle to three equal triangles.


Output
Output the x and y coordinates of the expected point in one line separate by a
space. Keep 3 digits after the decimal point.

 

Sample Input
0.0 0.0 0.0 6.0 6.0 0.0


Sample Output
1.000 2.000

 

      这道题算得上一道计算几何题,题目大概意思是:给你三个顶点的笛卡尔坐标,你的任务是在三角形内找到一点P,使得P与三个顶点的连线所分割的三角形面积比例为1/2 : 1/3 : 1/6,输出这个P点的坐标。

     这题很多人貌似一看就想到设P点坐标为(x0,y0),然后用海伦公式求出三个面的面积,然后列方程解出P点。但是这个思路不容易实现为算法,所以,需要找到一个更好的方法。

     可以看出,若做出三角形三边的中位线,三等分线,六等分线,将交于一点,该点即为所求的P点。具体实现的时候可以用向量的运算求P点,可以简化很多运算。

原创粉丝点击