题意:给定 n 个坐标,问你三个共线的有多少组。

析:这个题真是坑啊,写着 n <= 770,那么一秒时间,三个循环肯定超时啊,我一直不敢写了,换了好几种方法都WA了,也不知道为什么,在比赛时坑我了两个多小时,

最后看到那么多过的,就想试试,真的AC ,三个循环一点没优化,竟然才150多毫秒,。。。。POJ的数据真是水啊。

没什么好说的,只要三个循环,然后判断斜率就好了。

代码如下:

#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <string>
#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-11;
const int maxn = 770 + 5;
struct Node{
int id1, id2, id3;
Node(int a, int b, int c) : id1(a), id2(b), id3(c) { }
bool operator < (const Node &p) const{
if(id1 != p.id1) return id1 < p.id1;
else if(id2 != p.id2) return id2 < p.id2;
else return id3 < p.id3;
}
};
struct node{
int id, x, y;
};
struct node1{
int id;
double rad;
bool operator < (const node1 &p) const{
return rad < p.rad || (p.rad == rad && id < p.id);
}
}; double Fabs(double x){
return x < 0.0 ? -x : x;
} vector<Node> ans;
node a[maxn]; int main(){
int n, x, y, c;
scanf("%d", &n);
for(int i = 0; i < n; ++i){
scanf("%d %d", &x, &y);
a[i].id = i+1;
a[i].x = x+1;
a[i].y = y+1;
} for(int i = 0; i < n; ++i){
for(int j = i+1; j < n; ++j){
for(int k = j+1; k < n; ++k){
if((a[i].y-a[j].y)*(a[i].x-a[k].x) == (a[i].y-a[k].y)*(a[i].x-a[j].x)){
ans.push_back(Node(a[i].id, a[j].id, a[k].id));
}
}
}
} // sort(ans.begin(), ans.end());
printf("%d\n", ans.size());
for(int i = 0; i < ans.size(); ++i)
printf("%d %d %d\n", ans[i].id1, ans[i].id2, ans[i].id3);
return 0;
} /*
6
1 2
1 3
1 4
1 5
1 6
1 1
*/

POJ 3174 Alignment of the Planets (暴力求解)的更多相关文章

  1. POJ 3175 Finding Bovine Roots (暴力求解)

    题意:给定一串数字,问你这是一个数字开方根得到的前几位,问你是哪个数字.析:如果 x.123... 这个数字的平方是一个整数的话,那必然sqr(x.124) > ceil(sqr(x.123)) ...

  2. POJ 1562(L - 暴力求解、DFS)

    油田问题(L - 暴力求解.DFS) Description The GeoSurvComp geologic survey company is responsible for detecting ...

  3. 逆向暴力求解 538.D Weird Chess

    11.12.2018 逆向暴力求解 538.D Weird Chess New Point: 没有读好题 越界的情况无法判断,所以输出任何一种就可以 所以他给你的样例输出完全是误导 输出还搞错了~ 输 ...

  4. 隐型马尔科夫模型(HMM)向前算法实例讲解(暴力求解+代码实现)---盒子模型

    先来解释一下HMM的向前算法: 前向后向算法是前向算法和后向算法的统称,这两个算法都可以用来求HMM观测序列的概率.我们先来看看前向算法是如何求解这个问题的. 前向算法本质上属于动态规划的算法,也就是 ...

  5. BestCoder Round #79 (div.2)-jrMz and angles,,暴力求解~

    jrMz and angle       Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536/65536 K (Java/Other ...

  6. hdu6570Wave (暴力求解)

    Problem Description Avin is studying series. A series is called "wave" if the following co ...

  7. <字符串匹配>KMP算法为何比暴力求解的时间复杂度更低?

    str表示文本串,m表示模式串; str[i+j] 和 m[j] 是正在进行匹配的字符; KMP的时间复杂度是O(m+n)  ,  暴力求解的时间复杂度是O(m*n) KMP利用了B[0:j]和A[i ...

  8. 暴力求解——POJ 1321 棋盘问题

    Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子 ...

  9. POJ 3174 暴力枚举

    思路: 暴力枚举三个点 判一判 搞定 (x1*y1=x2*y2) x1.y1.x2.y2为他们两两的差 //By SiriusRen #include <cstdio> using nam ...

随机推荐

  1. java MVC设计模式

    MVC(Model View Control)模型-视图-控制器 一.MVC与模板概念的理解 MVC本来是存在于Desktop程序中的,M是指数据模型,V是指用户界面,C则是控制器.使用MVC的目的是 ...

  2. tableView的设置

    TableView的设置 1.设置table头部和底部的view // 底部(宽度固定是320) tableView.tableFooterView = footer; // 头部(宽度固定是320) ...

  3. WMware 10 Ubuntu 12.04 进入Unity模式

    /********************************************************************* * WMware 10 Ubuntu 12.04 进入Un ...

  4. 20160203.CCPP体系详解(0013天)

    程序片段(01):数组.c+02.数组初始化语法.c 内容概要:数组 ///01.数组.c #include <stdio.h> #include <stdlib.h> //0 ...

  5. 剑指offer-第二章排序之年龄排序

    题目:对某个公司的人的年龄(0-99)进行排序,该公司的总人数为几万人.要求时间复杂度为O(n),可以辅助O(n)的空间. 思路:实现函数为void SortAge(int ages[],int le ...

  6. Linux下ll命令与ls -l

    还大三Linux课的债. 1.ll命令用于显示当前文件下非隐藏文件的详情 查询结果分为7栏: 1)如' -rw-r--r--' 表示三种用户对该文件的不同权限: r:可读:w:可写:x:可执行 其中第 ...

  7. 【转】Xcode添加静态库以及编译选项配置常见问题

    原文网址:http://www.cnblogs.com/Quains/p/3276425.html 一,Xcode编译出现Link错误,出现"duplicate symbols for ar ...

  8. beginUpdates和endUpdates

    我们在做UITableView的修改,删除,选择时,需要对UITableView进行一系列的动作操作. 这样,我们就会用到 [tableView beginUpdates]; if (newCount ...

  9. spring mvc 异常统一处理方式

    springMVC提供的异常处理主要有两种方式: 一种是直接实现自己的HandlerExceptionResolver: 另一种是使用注解的方式实现一个专门用于处理异常的Controller——Exc ...

  10. linux下使用go-oci8

    地址:https://github.com/wendal/go-oci8 它是 https://github.com/mattn/go-oci8 的分支. win下安装步骤参考:http://www. ...