zoukankan      html  css  js  c++  java
  • POJ 3668 Game of Lines (暴力,判重)

    题意:给定 n 个点,每个点都可以和另一个点相连,问你共有多少种不同斜率的直线。

    析:那就直接暴力好了,反正数也不大,用set判重就好,注意斜率不存在的情况。

    代码如下:

    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    using namespace std ;
    
    typedef long long LL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const double inf = 0x3f3f3f3f3f3f3f;
    const double eps = 1e-8;
    const int maxn = 30000 + 5;
    const int dr[] = {0, 0, -1, 1};
    const int dc[] = {-1, 1, 0, 0};
    int m, n;
    inline bool is_in(int r, int c){
        return r >= 0 && r < n && c >= 0 && c < m;
    }
    int x[maxn], y[maxn];
    set<double> sets;
    
    int main(){
        while(scanf("%d", &n) == 1){
            sets.clear();
            for(int i = 0; i < n; ++i)  scanf("%d %d", &x[i], &y[i]);
            for(int i = 0; i < n; ++i)
                for(int j = i+1; j < n; ++j)
                    if(x[i] == x[j])  sets.insert(inf);
                    else  sets.insert((y[i]-y[j])*1.0/(x[i]*1.0-x[j]*1.0));
            printf("%d
    ", sets.size());
        }
        return 0;
    }
    
  • 相关阅读:
    053-606
    053-605
    1019 General Palindromic Number (20分)
    1208. 翻硬币
    754. 平方矩阵 II
    1346. 回文平方
    680. 剪绳子
    1227. 分巧克力
    756. 蛇形矩阵
    429. 奖学金
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5754026.html
Copyright © 2011-2022 走看看