• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
dwtfukgv
博客园    首页    新随笔    联系   管理    订阅  订阅
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\n", sets.size());
    }
    return 0;
}

 

posted on 2016-08-09 17:25  dwtfukgv  阅读(303)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3