zoukankan      html  css  js  c++  java
  • poj3668

    简单题

    View Code
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    
    const int maxn =205;
    
    struct Point
    {
        int x, y;
    }slope[maxn * maxn], point[maxn];
    
    int n, tot;
    
    bool operator == (const Point &a, const Point &b)
    {
        return a.x == b.x && a.y == b.y;
    }
    
    bool operator < (const Point &a, const Point &b)
    {
        if (a.x == b.x)
            return a.y < b.y;
        return a.x < b.x;
    }
    
    void input()
    {
        scanf("%d", &n);
        for (int i = 0; i < n; i++)
            scanf("%d %d", &point[i].x, &point[i].y);
    }
    
    int gcd(int a, int b)
    {
        b = b % a;
        while (b)
        {
            a = a % b;
            swap(a, b);
        }
        return a;
    }
    
    void simplify(int &x, int &y)
    {
        if (x == 0)
        {
            y = 1;
            return;
        }
        if (y == 0)
        {
            x = 1;
            return;
        }
        if (y < 0)
        {
            x = -x;
            y = -y;
        }
        int g = gcd(x < 0 ? -x : x, y);
        x /= g;
        y /= g;
    }
    
    void work()
    {
        tot = 0;
        for (int i = 0; i < n - 1; i++)
            for (int j = i + 1; j < n; j++)
            {
                slope[tot].x = point[j].x - point[i].x;
                slope[tot].y = point[j].y - point[i].y;
                simplify(slope[tot].x, slope[tot].y);
    //            printf("%d %d\n", slope[tot].x, slope[tot].y);
                tot++;
            }
    }
    
    int main()
    {
    //    freopen("t.txt", "r", stdin);
        input();
        work();
        sort(slope, slope + tot);
        tot = unique(slope, slope + tot) - slope;
        printf("%d\n", tot);
        return 0;
    }
  • 相关阅读:
    SQL数据类型详解
    将Excel表格导入DataTable的方法
    .net的反射机制
    经典SQL语句大全(一)
    c# Invoke和BeginInvoke 区别
    c#中两种常用的异步调用方法
    SQL存储过程参数问题
    API 函数大全(下)
    API函数大全 (上)
    javascript 常用function
  • 原文地址:https://www.cnblogs.com/rainydays/p/2573206.html
Copyright © 2011-2022 走看看