Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- #include <cmath>
- const double kEps = 1e-7;
- int main() {
- double x1, y1, x2, y2, x3, y3;
- std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
- const int minX = std::floor(std::min(x1, std::min(x2, x3)));
- const int minY = std::floor(std::min(y1, std::min(y2, y3)));
- const int maxX = std::ceil(std::max(x1, std::max(x2, x3)));
- const int maxY = std::ceil(std::max(y1, std::max(y2, y3)));
- double a = std::sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
- double b = std::sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3));
- double c = std::sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3));
- double p = (a + b + c) / 2;
- double s = std::sqrt(p * (p - a) * (p - b) * (p - c));
- int cnt = 0;
- for (int x = minX; x <= maxX; ++x) {
- for (int y = minY; y <= maxY; ++y) {
- double a1 = std::sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
- double a2 = std::sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2));
- double a3 = std::sqrt((x - x3) * (x - x3) + (y - y3) * (y - y3));
- double p1 = (a + a1 + a2) / 2;
- double s1 = std::sqrt(p1 * (p1 - a) * (p1 - a1) * (p1 - a2));
- double p2 = (b + a2 + a3) / 2;
- double s2 = std::sqrt(p2 * (p2 - b) * (p2 - a2) * (p2 - a3));
- double p3 = (c + a1 + a3) / 2;
- double s3 = std::sqrt(p3 * (p3 - c) * (p3 - a1) * (p3 - a3));
- if (std::abs(s1 + s2 + s3 - s) < kEps) {
- ++cnt;
- }
- }
- }
- std::cout << cnt;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement