就是给一个三角形,然后给出一些关系,以及一些点的坐标,最后求一个三角形面积就好了。
我的做法:
用向量的方法推出离线段一个端点最近的三等分点的表达式
用行列式解线性方程推出求两直线交点的表达式
用叉积求三角形面积
用小数点后第一位对整数部分进行四舍五入求得离这个实数最近的整数
我的代码如下:
#include<iostream>
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
struct Dot
{
double x,y;
Dot(){}
Dot(double a,double b){x=a,y=b;}
};
Dot operator - (Dot a,Dot b){return Dot(b.x-a.x,b.y-a.y);}
double operator * (Dot a,Dot b){return a.x*b.y-b.x*a.y;}
double area(Dot a,Dot b,Dot c){return fabs((b-a)*(c-a));}
Dot cross(Dot a,Dot b,Dot c,Dot d)
{
double e,f,g,h,i,j,k,l,m;
e=b.y-a.y;f=a.x-b.x;g=a.x*b.y-a.y*b.x;
h=d.y-c.y;i=c.x-d.x;j=c.x*d.y-c.y*d.x;
k=Dot(e,h)*Dot(f,i);
l=Dot(g,j)*Dot(f,i);
m=Dot(e,h)*Dot(g,j);
return Dot(l/k,m/k);
}
Dot d3(Dot a,Dot b){return Dot((2*a.x+b.x)/3,(2*a.y+b.y)/3);}
int main()
{
int n,ans;
Dot a,b,c,d,e,f,p,q,r;
cin>>n;
while(n--)
{
cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y;
d=d3(b,c);
e=d3(c,a);
f=d3(a,b);
p=cross(b,e,d,a);
q=cross(b,e,c,f);
r=cross(d,a,c,f);
ans=0.5+area(p,q,r)/2;
printf("%d\n",ans);
}
}
原题:
Time limit: 1.000 seconds
Problem A
Triangle Fun
Input: Standard Input
Output: Standard Output
In the picture below you can seea triangle ABC. Point D, E and F divides the sides BC, CA and AB into ratio 1:2respectively. That is CD=2BD, AE=2CE and BF=2AF. A, D; B, E and C, F areconnected. AD and BE intersects at P, BE and CF intersects at Q and CF and ADintersects at R.
So now a new triangle PQR isformed. Given triangle ABC your job is to find the area of triangle PQR.
Input
First line of the input filecontains an integer N (0<N<1001) which denotes how many sets of inputsare there. Input for each set contains six floating-point numberAx, Ay, Bx, By, Cx, Cy. (0≤Ax, Ay, Bx, By,Cx,Cy≤10000) in one line line. These six numbersdenote that the coordinate of points A, B and C are (Ax, Ay), (Bx, By) and (Cx, Cy) respectively. A, B and C willnever be collinear.
Output
For each setof input produce one line of output. This one line contains an integer AREA.Here AREA is the area of triangle PQR, rounded to the nearest integer.
Sample Input
2 3994.707 9251.677 4152.916 7157.810 5156.835 2551.972 6903.233 3540.932 5171.382 3708.015 213.959 2519.852 |
Output forSample Input
98099
206144