您的位置:首页 > 其它

HDOJ---4242||HNNUOJ Rancher's Gift[四边形分割的面积]

2012-09-02 17:07 169 查看

Rancher's Gift

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 26 Accepted Submission(s): 21


[align=left]Problem Description[/align]
Rancher Joel has a tract of land in the shape of a convex quadrilateral that the wants to divide among his sons Al, Bob, Chas and Dave, who wish to continue ranching on their portions, and his daughter Emily, who wishes to grow vegetables on her portion.

The center of the tract is most suitable for vegetable farming so Joel decides to divide the land by drawing lines from each corner (A, B, C, D in counter clockwise order) to the center of an opposing side (respectively A', B', C' and D') Each son would receive one of the triangular sections and Emily would receive the central quadrilateral section. As shown in the figure, Al's tract is to be bounded by the line from A to B, the line from A to the midpoint of BC and the line from B to the midpoint of CD' Bob&s ract is to be bounded by the line from B to C, the line from B to the midpoint of CD and the line from C to the midpoint of DA, and so on.



Your job is to write a program that will help Rancher Joel determine the area of each child's tract and the length of the fence he will have to put around Emily's parcel to keep her brothers' cows out of her crops.

For his problem, A will always be at (0, 0) and B will always be at (x, 0). Coordinates will be in rods (a rod is 16.5 feet).The returned areas should be in acres to 3 decimal places (an acre is 160 square rods) and the length of the fence should be in feet, rounded up to the next foot.

[align=left]Input[/align]
The first line of input contains a single integer P( 1 <= P <= 1000),which is the number of data sets that follow. Each data set is a single line that contains of a decimal integer followed by five (5) space separated floating-point values. The first (integer) value is the data set number, N. The floating-point values are B.x, C.x, C.y, D.x and D.y in that order (where V.x indicates the x coordinate of V and V.y indicates the y coordinate of V). Recall that the y coordinate of B is always zero (0). The supplied coordinates will always specify a valid convex quadrilateral.

[align=left]Output[/align]
For each data set there is a single line of output. It contains the data set number, N , followed by a single space followed by five(5) space separated floating-point values to three(3) decimal place accuracy, followed by a single space and a decimal integer! The floating-point values are the areas in acres of the properties of Al, Bob, Chas, Dave, and Emily respectively. The final integer is the length of fence in feet required to fence in Emily's property (rounded up to the next foot).

[align=left]Sample Input[/align]

3 1 200 250 150 -50 200 2 200 200 100 0 100 3 201.5 157.3 115.71 -44.2 115.71

[align=left]Sample Output[/align]

1 35.000 54.136 75.469 54.167 54.666 6382 2 25.000 25.000 25.000 25.000 25.000 4589 3 29.144 29.144 29.144 29.144 29.144 4937

[align=left]Source[/align]
2011 Greater New York Regional

求四边形分割成五块区域的面积以及求中间区域的周长

哈哈,神奇的A了!

code:

#include<iostream>
#include<cmath>
using namespace std;

struct node
{
double x,y;
}node[100];

double area[5];
double t1,t2,t3,t4,t5;
double areasum;
double lensum;
double fun4(int cur1,int cur2);
void fun(int cur,double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4)
{
node[cur].x=((x1-x2)*x4*(y3-y4)-x2*(x3-x4)*(y1-y2)+(y2-y4)*(x1-x2)*(x3-x4))/((x1-x2)*(y3-y4)-(y1-y2)*(x3-x4));
node[cur].y=(((x4-x2)*(y1-y2)+(y2-y4)*(x1-x2))*(y3-y4)+y4*(((x1-x2)*(y3-y4)-(y1-y2)*(x3-x4))))/((x1-x2)*(y3-y4)-(y1-y2)*(x3-x4));
}

double ab_s(double a)
{
if(a<0)
{
return -a;
}
return a;
}

double funt(double x1,double y1,double x2,double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

void fun1(int cur,double x1,double y1,double x2,double y2,double x,double y)
{
double d;
double len1,len2,len3,p;
len1=funt(x1,y1,x2,y2);
len2=funt(x1,y1,x,y);
len3=funt(x2,y2,x,y);
p=(len1+len2+len3)/2.0;
area[cur]=sqrt(p*(p-len1)*(p-len2)*(p-len3));
}

double funw(double x1,double y1,double x2,double y2,double x,double y)
{
double d;
double len1,len2,len3,p;
len1=funt(x1,y1,x2,y2);
len2=funt(x1,y1,x,y);
len3=funt(x2,y2,x,y);
p=(len1+len2+len3)/2.0;
return sqrt(p*(p-len1)*(p-len2)*(p-len3));
}

void fun2()
{
double t1,t2;
t1=funw(node[0].x,node[0].y,node[1].x,node[1].y,node[3].x,node[3].y);
t2=funw(node[1].x,node[1].y,node[2].x,node[2].y,node[3].x,node[3].y);
areasum=t1+t2;
areasum-=(area[0]+area[1]+area[2]+area[3]);
}

void fun3()
{
lensum=(fun4(8,9)+fun4(9,10)+fun4(10,11)+fun4(11,8));
}

double fun4(int cur1,int cur2)
{
return sqrt((node[cur1].x-node[cur2].x)*(node[cur1].x-node[cur2].x)+(node[cur1].y-node[cur2].y)*(node[cur1].y-node[cur2].y));
}

int main()
{
int t;
int cases;
scanf("%d",&t);
while(t--)
{
memset(node,0,sizeof(node));
scanf("%d%lf%lf%lf%lf%lf",&cases,&t1,&t2,&t3,&t4,&t5);
node[0].x=0;
node[0].y=0;
node[1].x=t1;
node[1].y=0;
node[2].x=t2;
node[2].y=t3;
node[3].x=t4;
node[3].y=t5;

node[4].x=(t1)/2.0;
node[4].y=0;;
node[5].x=(t1+t2)/2.0;;
node[5].y=t3/2.0;
node[6].x=(t2+t4)/2.0;
node[6].y=(t3+t5)/2.0;
node[7].x=t4/2.0;
node[7].y=t5/2.0;

fun(8,node[0].x,node[0].y,node[5].x,node[5].y,node[3].x,node[3].y,node[4].x,node[4].y);
fun(9,node[0].x,node[0].y,node[5].x,node[5].y,node[1].x,node[1].y,node[6].x,node[6].y);
fun(10,node[7].x,node[7].y,node[2].x,node[2].y,node[1].x,node[1].y,node[6].x,node[6].y);;
fun(11,node[7].x,node[7].y,node[2].x,node[2].y,node[3].x,node[3].y,node[4].x,node[4].y);

fun1(0,node[0].x,node[0].y,node[1].x,node[1].y,node[9].x,node[9].y);
fun1(1,node[1].x,node[1].y,node[2].x,node[2].y,node[10].x,node[10].y);
fun1(2,node[2].x,node[2].y,node[3].x,node[3].y,node[11].x,node[11].y);
fun1(3,node[3].x,node[3].y,node[0].x,node[0].y,node[8].x,node[8].y);

fun2();
fun3();
lensum=lensum*16.5;
if(lensum!=int(lensum))
lensum=int(lensum)+1;
printf("%d %.3f %.3f %.3f %.3f %.3f %.0f\n",cases,area[0]/160,area[1]/160,area[2]/160,area[3]/160,areasum/160,lensum);
}
return 0;
}
/*
3
1 200 250 150 -50 200
2 200 200 100 0 100
3 201.5 157.3 115.71 -44.2 115.71
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: