画直线

  题目大意:给定一些点集,要你找两点之间的连线不平行的有多少条

  数据量比较少,直接暴力枚举,然后放到set查找即可

 #include <iostream>
#include <functional>
#include <algorithm>
#include <set> using namespace std; static struct _p_set
{
long double x, y;
}points[];
set<long double>lines; int gcd(const int, const int); int main(void)
{
int point_sum, cut;
long double tmp;
//pair<int,int>tmp;
while (~scanf("%d", &point_sum))
{
lines.clear();
for (int i = ; i < point_sum; i++)
scanf("%lf%lf", &points[i].x, &points[i].y);
for (int i = ; i < point_sum; i++)
{
for (int j = i + ; j < point_sum; j++)
{
if ((points[i].x - points[j].x) != )
tmp = (points[i].y - points[j].y) / (points[i].x - points[j].x);
else
tmp = (long double)INT_MAX;
lines.insert(tmp);
}
}
printf("%d\n", lines.size());
} return EXIT_SUCCESS;
}

  

  在讨论版那里还找到了一种很新奇的做法,可以无视除数是0和精度的问题

 #include <iostream>
#include <functional>
#include <algorithm>
#include <set> using namespace std; static struct _p_set
{
int x, y;
}points[];
set<pair<int,int>>lines; int gcd(const int, const int); int main(void)
{
int point_sum, cut;
pair<int,int>tmp;
while (~scanf("%d", &point_sum))
{
lines.clear();
for (int i = ; i < point_sum; i++)
scanf("%d%d", &points[i].x, &points[i].y);
for (int i = ; i < point_sum; i++)
{
for (int j = i + ; j < point_sum; j++)
{
cut = gcd(points[i].y - points[j].y, points[i].x - points[j].x);
tmp.first = (points[i].y - points[j].y) / cut;
tmp.second = (points[i].x - points[j].x) / cut;
lines.insert(tmp);
}
}
printf("%d\n", lines.size());
}
return EXIT_SUCCESS;
} int gcd(const int a, const int b)
{
if (b == )
return a;
return gcd(b, a%b);
}

  

  其实时间差不多

Enum:Game of Lines(POJ 3668)的更多相关文章

  1. POJ 3668 Game of Lines (暴力,判重)

    题意:给定 n 个点,每个点都可以和另一个点相连,问你共有多少种不同斜率的直线. 析:那就直接暴力好了,反正数也不大,用set判重就好,注意斜率不存在的情况. 代码如下: #include <c ...

  2. Divide and conquer:Telephone Lines(POJ 3662)

    电话线 题目大意:一堆电话线要你接,现在有N个接口,总线已经在1端,要你想办法接到N端去,电话公司发好心免费送你几段不用拉网线,剩下的费用等于剩余最长电话线的长度,要你求出最小的费用. 这一看又是一个 ...

  3. Intersecting Lines - POJ 1269(判断平面上两条直线的关系)

    分析:有三种关系,共线,平行,还有相交,共线和平行都可以使用叉积来进行判断(其实和斜率一样),相交需要解方程....在纸上比划比划就出来了....   代码如下: ================== ...

  4. Intersecting Lines POJ 1269

    题目大意:给出两条直线,每个直线上的两点,求这两条直线的位置关系:共线,平行,或相交,相交输出交点. 题目思路:主要在于求交点 F0(X)=a0x+b0y+c0==0; F1(X)=a1x+b1y+c ...

  5. Telephone Lines POJ - 3662 (二分+spfa)

    Farmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is uncoop ...

  6. 判断线段之间的关系(D - Intersecting Lines POJ - 1269 )

    题目链接:https://vjudge.net/contest/276358#problem/D 题目大意:每一次给你两条直线,然后问你这两条直线的关系(平行,共线,相交(输出交点)). 具体思路:先 ...

  7. Enum:EXTENDED LIGHTS OUT(POJ 1222)

    亮灯 题目大意:有一个5*6的灯组,按一盏灯会让其他上下左右4栈和他自己灯变为原来相反的状态,要怎么按才会把所有的灯都按灭? 3279翻版题目,不多说,另外这一题还可以用其他方法,比如DFS,BFS, ...

  8. Enum:Backward Digit Sums(POJ 3187)

    反过来推 题目大意:就是农夫和这只牛又杠上了(怎么老是牛啊,能换点花样吗),给出一行数(从1到N),按杨辉三角的形式叠加到最后,可以得到一个数,现在反过来问你,如果我给你这个数,你找出一开始的序列(可 ...

  9. POJ 3668 枚举?

    枚举两点,算一下斜率 sort一遍 判个重 输出解 25行 搞定- //By SiriusRen #include <cmath> #include <cstdio> #inc ...

随机推荐

  1. Linux服务器管理: 系统管理:进程文件信息lsof

    lsof命令 列出进程打开或使用的文件信息 [root@loclahost/]#lsof [选项] 选项: -c 字符串: 只列出以字符串开头的进程打开的文件 -u 用户名: 只列出某个用户的进程打开 ...

  2. Backbone☞View中的events...click事件失效

    <div id="container"> <input type="button" id="test_click" val ...

  3. 北京程序员 VS 硅谷程序员(转)

    夫妻双码农,北京 or 硅谷,值得吗? http://mp.weixin.qq.com/s?__biz=MzA5MzE4MjgyMw==&mid=401228574&idx=1& ...

  4. IE hack

    .hack{ color:#fff;background:#; background:#06f\; /* all IE */ background:#\; /* IE8-9 */ background ...

  5. Oracle 数据库1046事件

    例子: session 2: SQL> connect test/test Connected. select * from v$mystat where rownum=1; 143 selec ...

  6. 小技巧-a标签去除蓝圈

    可以看到,蓝色的边框破坏了页面的整体美感,很多时候我们都是不需要的.通过设置相应的css可以去除点击过后的蓝色边框. map area { outline: none; } 效果如图,点击过后厌人的蓝 ...

  7. iOS 不规则的ImageView

    http://blog.csdn.net/kevinpake/article/details/41205715 我们在做iOS开发的时候,往往需要实现不规则形状的头像,如: 那如何去实现? 通常图片都 ...

  8. PHP学习路线

    0x1 0x2

  9. java中的jComBox的基本用法

    jComBox获取选中的字符串 getSelectedItem().toString()返回一个字符串 getSelectedItem()返回一个对象. getSelectedIndex()得到选择值 ...

  10. Android 异步消息处理机制解析

    Android 中的异步消息处理主要由四个部分组成,Message.Handler.MessageQueue.Looper.下面将会对这四个部分进行一下简要的介绍. 1. Message: Messa ...