• poj2954


    Pick公式:平面上以格子点为顶点的简单多边形,如果边上的点数为on,内部的点数为in,则它的面积为area=on/2+in-1
    利用gcd求每个边上的点数。

    View Code
    #include <iostream>
    #include <cstdlib>
    #include <cstring>
    #include <cstdio>
    using namespace std;

    struct Point
    {
    int x, y;
    }point[3];

    void input()
    {
    for (int i = 0; i < 3; i++)
    scanf("%d%d", &point[i].x, &point[i].y);
    int ret = 0;
    for (int i = 0; i < 3; i++)
    ret |= point[i].x | point[i].y;
    if (!ret)
    exit(0);
    }

    int xmult(Point a, Point b, Point c)
    {
    return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);
    }

    int gcd(int x, int y)
    {
    if (!x || !y)
    return x > y ? x : y;
    for (int t; t = x % y; x = y, y = t);
    return y;
    }

    void work()
    {
    int area = abs(xmult(point[0], point[1], point[2]));
    int on = 0;
    for (int i = 0; i < 3; i++)
    on += gcd(abs(point[i % 3].x - point[(i + 1)%3].x), abs(point[i % 3].y - point[(i + 1)%3].y));
    int in = (area - on) / 2 + 1;
    printf("%d\n", in);
    }

    int main()
    {
    //freopen("t.txt", "r", stdin);
    while (1)
    {
    input();
    work();
    }
    return 0;
    }

  • 相关阅读:
    hduoj 1865 1string 【大数】【菲波那切数列】
    poj 1664 放苹果【M的N划分】
    新年第一篇
    3、XCode: 如何添加自定义代码片段
    2、文件夹
    1、获取当前屏幕显示的页面
    运算符
    表单数据接收
    PHP进入MySQL数据库
    my SQL认识和进入
  • 原文地址:https://www.cnblogs.com/rainydays/p/2202118.html
Copyright © 2020-2023  润新知