BUPTOJ85 Three Points On A Line
来源:互联网 发布:iphone6s不能更新软件 编辑:程序博客网 时间:2024/06/06 18:21
PS:居然在论坛听说,有考研400分的大神,不、会、写、代、码!!
BUPT83 A+B 无压力秒杀!!!First Blood!!
BUPT84 Single Number 本来以为能轻松Double Kill的。。没想到跪在超时上了,到现在还没想明白
BUPT85 Three Points On A Line 没想到连跪两题,有辱ACM业余队员称号(低调低调) = =
BUPT86...
不行!!必须把BUPT85做出来!!决不能再这样水下去了!!!我是要成为大牛的男人!!于是——
**********************************
上面不是分割线,是我说的话。解决了看错题、拼写错误等低端失误之后,还是答案错误。最后,我只好百度了。。。看到了一大牛写的解答。。暴力归暴力,我终于知道自己哪错了。
http://blog.csdn.net/birdstorm_s/article/details/21017411
之所以称之为大牛,是因为大牛总是在字里行间体现水平。他说有O(n^2)的算法,这个可是我百度好久之后才找到的,3SUM Hard问题。。
http://cs.smith.edu/~orourke/TOPP/P11.html#Problem.11
我确定我这不是算法问题,我怀疑是float的精度问题。。。
我判断三点共线用的斜率,但斜率就要除法,两个三位小数精度的数除完之后的精度是什么来着?好像物理实验课讲过。。可惜已经忘了。。我试了10^-4、10^-5,都报错。
大牛的判断方法把斜率相等的公式推导了一下,变成了一个乘法和减法的算式。这个好,不仅效率比除法高,而且精度易计算,10^-6。
判断方法改后,直接通过了。。仅以此文记这艰难的AC,展望更加艰难的未来╮(╯▽╰)╭
/*USER_ID: test#aa3615058PROBLEM: 85SUBMISSION_TIME: 2014-03-17 23:06:13*/#include <iostream>#include <math.h>using namespace std; typedef struct Point{ float x; float y;}Point; bool isOnALine(Point a, Point b, Point c);float slope(Point a, Point b); int main() { int caseCount; bool onaline; cin>>caseCount; for(int i = 0; i < caseCount; i++) { int pointCount; cin>>pointCount; Point ps[pointCount]; for(int j = 0; j < pointCount; j++) { cin >> ps[j].x >> ps[j].y; } onaline = false; if(pointCount >= 3) { Point a,b,c; for(int k = 0; k < pointCount && !onaline; k++) { a = ps[k]; for(int l = k + 1; l < pointCount && !onaline; l++) { b = ps[l]; for(int g = l + 1; g < pointCount && !onaline; g++) { c = ps[g]; if(isOnALine(a,b,c)) { onaline = true; break; } } } } } if(onaline) { cout << "Yes" << endl; } else { cout << "No" << endl; } } return 0;} bool isOnALine(Point a, Point b, Point c) { return (fabs(a.x * c.y + b.x * a.y + b.y * c.x - b.x * c.y - a.y * c.x - b.y * a.x) <= 1e-6);} float slope(Point a, Point b) { return (a.y - b.y) / (a.x - b.x);}
- BUPTOJ85 Three Points On A Line
- BUPT OJ85 Three Points On A Line
- 85. Three Points On A Line
- 北邮OJ 85. Three Points On A Line
- bupt 85 Three Points On A Line(水题)
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- Max Points On a Line
- Max Points on a Line
- Max Points on a Line
- Max Points on a Line
- max points on a line
- Max Points on a Line
- Max Points on a Line
- [Linux高级编程]内存管理&映射&分配
- 修改 ubuntu 默认启动项
- ZOJ-1095
- 定义input type=file 样式的方法
- C++输入cin详解
- BUPTOJ85 Three Points On A Line
- ios basic 2.2:working with foundation
- Qt第三方库QML-Box2D——使用它创建一个飞翔的蝙蝠
- Mac来了
- httpclient 如何保持会话
- 直接在DataGridView中添加修改数据的问题
- win7 右下角显示时间日期
- cogs 数列
- eclipse的快捷键