zoukankan      html  css  js  c++  java
  • P2665 [USACO08FEB]连线游戏Game of Lines

    题目描述

    Farmer John has challenged Bessie to the following game: FJ has a board with dots marked at N (2 ≤ N ≤ 200) distinct lattice points. Dot i has the integer coordinates Xi and Yi (-1,000 ≤ Xi ≤ 1,000; -1,000 ≤ Yi ≤ 1,000).

    Bessie can score a point in the game by picking two of the dots and drawing a straight line between them; however, she is not allowed to draw a line if she has already drawn another line that is parallel to that line. Bessie would like to know her chances of winning, so she has asked you to help find the maximum score she can obtain.

    游戏开始的时 候,FJ会给贝茜一块画着N (2 <= N <= 200)个不重合的点的木板,其中第i个点 的横、纵坐标分别为X_i和Y_i (-1,000 <= X_i <=1,000; -1,000 <= Y_i <= 1,000)。 贝茜可以选两个点画一条过它们的直线,当且仅当平面上不存在与画出直线 平行的直线。游戏结束时贝茜的得分,就是她画出的直线的总条数。为了在游戏 中胜出,贝茜找到了你,希望你帮她计算一下最大可能得分。

    输入输出格式

    输入格式:

    第1行: 输入1个正整数:N

    第2..N+1行: 第i+1行用2个用空格隔开的整数X_i、Y_i,描述了点i的坐标

    输出格式:

    第1行: 输出1个整数,表示贝茜的最大得分,即她能画出的互不平行的线段数

    输入输出样例

    输入样例#1: 复制
    4 
     -1 1 
     -2 0 
     0 0 
     1 1
    输出样例#1: 复制
    4 

    说明

    贝茜能画出以下4种斜率的直线:-1,0,1/3以及1。

    USACO2008 Feb T1

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define inf 2147483647
    const ll INF = 0x3f3f3f3f3f3f3f3fll;
    #define ri register int
    template <class T> inline T min(T a, T b, T c)
    {
        return min(min(a, b), c);
    }
    template <class T> inline T max(T a, T b, T c)
    {
        return max(max(a, b), c);
    }
    template <class T> inline T min(T a, T b, T c, T d)
    {
        return min(min(a, b), min(c, d));
    }
    template <class T> inline T max(T a, T b, T c, T d)
    {
        return max(max(a, b), max(c, d));
    }
    #define pi acos(-1)
    #define me(x, y) memset(x, y, sizeof(x));
    #define For(i, a, b) for (int i = a; i <= b; i++)
    #define FFor(i, a, b) for (int i = a; i >= b; i--)
    #define mp make_pair
    #define pb push_back
    const int maxn = 100005;
    // name*******************************
    set<double>k;
    double x[300],y[300];
    int n;
    // function******************************
    
    //***************************************
    int main()
    {
        cin>>n;
        For(i,1,n)
        {
            cin>>x[i]>>y[i];
            For(j,1,i-1)
            {
                if(x[i]==x[j])
                    k.insert(inf);
                else
                    k.insert((y[i]-y[j])/(x[i]-x[j]));
            }
        }
        cout<<k.size();
        return 0;
    }
  • 相关阅读:
    网页表格或div层在网页中被撑开解决之道
    jquery把给定的json自动生成多级下拉框
    jquery理想菜单实现(显示全国省市区分级效果)
    正则表达式记录
    jQuery自定义插件
    js数组及其常用方法
    vue自定义组件
    GET和POST
    可变对象和不可变对象
    js 不同元素的同一属性运动
  • 原文地址:https://www.cnblogs.com/planche/p/8650444.html
Copyright © 2011-2022 走看看