Yes, the area of the triangle is from the coordinates of the three points ~ ~ http://abc002.contest.atcoder.jp/tasks/abc002_3
Even if you know the three-point coordinates, one point is not always (0,0) for convenience, and it seems to be very troublesome ...
I thought, but when I looked it up a little, I came across a story that one of them should be decided as (0,0).
A hint from the official during the time
3 points(0,0), (a,b), (c,d)The area of the triangle composed of|ad−bc|⁄2. (This tip was published one hour after the contest started. about it. Yes.
The code you submitted.py
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import time
import sys
import io
import re
import math
#start = time.time()
#start = time.clock()
(xa,ya, xb,yb, xc,yc) = map(int, raw_input().split())
xa=xa-xc
ya=ya-yc
xb=xb-xc
yb=yb-yc
xc,yc=0,0
j=(xa*yb)-(ya*xb)
if j<0: j=j*(-1)
S=j/2.0
print S
I decided to receive the three points as (xa, ya) (xb, yb) (xc, yc). xc,I decided to set yc to 0, so a,Subtract from each of b|ad−bc|Using the formula of ⁄2. However, it seems that the calculation will be strange if it is mixed with minus coordinates, so if it is less than 0, I multiplied it by -1. It seems that the area of the triangle is calculated by this method in other situations, so it will be useful later if you understand and save a cleaner writing style by looking at other people's submissions.
Recommended Posts