POJ 3174 Alignment of the Planets (暴力求解)
题意:给定 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 (暴力求解)的更多相关文章
- POJ 3175 Finding Bovine Roots (暴力求解)
题意:给定一串数字,问你这是一个数字开方根得到的前几位,问你是哪个数字.析:如果 x.123... 这个数字的平方是一个整数的话,那必然sqr(x.124) > ceil(sqr(x.123)) ...
- POJ 1562(L - 暴力求解、DFS)
油田问题(L - 暴力求解.DFS) Description The GeoSurvComp geologic survey company is responsible for detecting ...
- 逆向暴力求解 538.D Weird Chess
11.12.2018 逆向暴力求解 538.D Weird Chess New Point: 没有读好题 越界的情况无法判断,所以输出任何一种就可以 所以他给你的样例输出完全是误导 输出还搞错了~ 输 ...
- 隐型马尔科夫模型(HMM)向前算法实例讲解(暴力求解+代码实现)---盒子模型
先来解释一下HMM的向前算法: 前向后向算法是前向算法和后向算法的统称,这两个算法都可以用来求HMM观测序列的概率.我们先来看看前向算法是如何求解这个问题的. 前向算法本质上属于动态规划的算法,也就是 ...
- 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 ...
- hdu6570Wave (暴力求解)
Problem Description Avin is studying series. A series is called "wave" if the following co ...
- <字符串匹配>KMP算法为何比暴力求解的时间复杂度更低?
str表示文本串,m表示模式串; str[i+j] 和 m[j] 是正在进行匹配的字符; KMP的时间复杂度是O(m+n) , 暴力求解的时间复杂度是O(m*n) KMP利用了B[0:j]和A[i ...
- 暴力求解——POJ 1321 棋盘问题
Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子 ...
- POJ 3174 暴力枚举
思路: 暴力枚举三个点 判一判 搞定 (x1*y1=x2*y2) x1.y1.x2.y2为他们两两的差 //By SiriusRen #include <cstdio> using nam ...
随机推荐
- hadoop1常见配置含义
参数 取值 备注 fs.default.name NameNode ...
- linux sed 命令
转载:http://www.cnblogs.com/dong008259/archive/2011/12/07/2279897.html sed是一个很好的文件处理工具,本身是一个管道命令,主要是以行 ...
- mysql中批量替换数据库中的内容的sql
经过几次系统升级,遇到域名变了,文件存储目录变了,但之前被存到数据库里了,手动改太麻烦了,下面这个sql语句太给力了,屡试不爽. update table set body = replace(bod ...
- pcap文件的文件头的link type
http://www.tcpdump.org/linktypes.html Link-layer header type values LINKTYPE_ name LINKTYPE_ value C ...
- 解决WebSphere异常:SRVE0199E: 已获取了 OutputStream
dlg: 例如 在WebSphere这个目录下 /opt/IBM/WebSphere/AppServer/profiles/AppSrv01/temp/master1Node01/master1/gk ...
- Dev GridView 获取选中分组下的所有数据行 z
现在要在DevExpress 的GridView 中实现这样一个功能.就是判断当前的选中行是否是分组行,如果是的话就要获取该分组下的所有数据信息. 如下图(当选中红框中的分组行事.程序要获取该分组下的 ...
- 15stl模板
1.stack #include<iostream> #include<stdio.h> #include<stack> using namespace std; ...
- hdu 5253 最小生成树
赤裸裸最小生成树,没啥说的,我用kruskal过的 /* * Author : ben */ #include <cstdio> #include <cstdlib> #inc ...
- iOS学习笔记之回调(二)
写在前面 上一篇学习笔记中简单介绍了通过目标-动作对实现回调操作:创建两个对象timer和logger,将logger设置为timer的目标,timer定时调用logger的sayOuch函数.在这个 ...
- Unity 5 引擎收费版和免费版的区别(转)
最新Unity 5的Professional Edition(收费版)具备全新而强大的功能,除了全局动态光照或是最新的基于物理的着色器之外,也把原本分开销售的Team License放入,并含有12个 ...