AtCoder Beginner Contest # 002 C Problem

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

Tips

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

AtCoder Beginner Contest # 002 C Problem
AtCoder Beginner Contest 174 C Problem (Python)
AtCoder Regular Contest # 002 C Problem
AtCoder Beginner Contest 177
AtCoder Beginner Contest 179
AtCoder Beginner Contest 172
AtCoder Beginner Contest 180
AtCoder Beginner Contest 173
Atcoder Beginner Contest 153
AtCoder Beginner Contest 176 C Problem "Step" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 152 Review
AtCoder Beginner Contest 166 A Explanation of Problem "A? C" (Python3, C ++, Java)
AtCoder Beginner Contest 174 B Problem "Distance" Explanation (C ++, Python, Java)
AtCoder Beginner Contest 187 Note
AtCoder Beginner Contest 177 B Problem "Substring" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 160 Review
AtCoder Beginner Contest 178 Review
AtCoder Beginner Contest 180 Note
AtCoder Beginner Contest 166 Review
AtCoder Beginner Contest 182 Note
AtCoder Beginner Contest 167 A Problem "Registration" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 164 Review
AtCoder Beginner Contest 181 Review
AtCoder Beginner Contest 171 Review
AtCoder Beginner Contest 182 Review
AtCoder Beginner Contest 180 Review
AtCoder Beginner Contest 156 WriteUp
AtCoder Beginner Contest 177 Review
AtCoder Beginner Contest 168 Review
AtCoder Beginner Contest 179 Review
Solve AtCoder Beginner Contest 100-102
AtCoder Beginner Contest 167 Memorandum
AtCoder Beginner Contest 172 Review
AtCoder Beginner Contest 183 Note
AtCoder Beginner Contest 176 Review
AtCoder Beginner Contest 184 Note
AtCoder Beginner Contest 175 Review
AtCoder Beginner Contest 174 Review
AtCoder Beginner Contest 153 Review
AtCoder Beginner Contest 156 Review
AtCoder Beginner Contest 161 Review
AtCoder Beginner Contest 170 Review
AtCoder Beginner Contest 169 B Problem "Multiplication 2" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 165 Review
AtCoder Beginner Contest 173 Review
AtCoder Beginner Contest 188 Note
AtCoder Beginner Contest 155 Review
AtCoder Beginner Contest 162 Review
AtCoder Beginner Contest 170 A Problem "Five Variables" Explanation (C ++, Python, Java)
AtCoder Beginner Contest 176 A Explanation of problem "Takoyaki" (Python3, C ++, Java)
AtCoder Beginner Contest 175 B Problem "Making Triangle" Explanation (C ++, Python3, Java)
AtCoder Beginner Contest 175 A Problem "Rainy Season" Explanation (C ++, Python3, Java)
AtCoder Beginner Contest 176 B Problem "Multiple of 9" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 174 A Problem "Air Conditioner" Explanation (C ++, Python, Java)
AtCoder Beginner Contest 181 Participation Report
AtCoder Beginner Contest 175 Virtual entry
AtCoder Beginner Contest 161 Participation Report
AtCoder Beginner Contest 176 Participation Report
AtCoder Beginner Contest 154 Participation Report
AtCoder Beginner Contest # 003 Participation Note
AtCoder Beginner Contest 166 Participation Report