uva270 - Lining Up(暴力)
来源:互联网 发布:武汉蓝星软件 编辑:程序博客网 时间:2024/05/19 08:01
题目:uva270 - Lining Up
解题思路:对于每个点都计算一下,它与其他点的斜率,这样就可以判断与这个点在同一条直线的点。每个点都这样做,维护最大值就可以了。
注意斜率不存在的情况。
找相同斜率的时候用了multiset。
代码:
#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <set>using namespace std;const int N = 705;const double esp = 1e-9;int n;char str[N];double ki[N];int visit[N];multiset <double> K;struct NODE {double x, y;}node[N];double Max (const double a, const double b) { return a > b ? a: b; }double Fabs (const double a, const double b) { if (a > b)return a - b;return b - a;}int main () {int t;int cnt;int count;scanf ("%d%*c%*c", &t);while (t--) {n = 0;while (gets(str) != NULL && str[0] != '\0') {sscanf (str, "%lf%lf", &node[n].x, &node[n].y);n++;}cnt = 0;for (int i = 0; i < n; i++) {K.clear();count = 0;memset (visit, 0, sizeof (visit));for (int j = 0; j < n; j++) {if (i == j)continue;if (Fabs (node[i].x, node[j].x) <= esp) {count++;continue;}else ki[j] = (node[i].y - node[j].y) / (node[i].x - node[j].x); K.insert (ki[j]);visit[j] = 1; }for (int j = 0; j < n; j++) { if (visit[j]) { cnt = Max (cnt, K.count(ki[j]));// printf ("%d\n", K.count(ki[j])); }}cnt = Max (cnt, count);}printf ("%d\n", cnt + 1);if (t)printf ("\n");}return 0;}
0 0
- uva270 - Lining Up(暴力)
- uva270 - Lining Up
- uva270 Lining Up 搜索?
- UVA270- Lining Up
- UVA270-Lining Up
- UVALive5379 UVA270 Lining Up
- [排序&&模拟]Lining Up uva270
- uva270 - Lining Up(几何 - 最大共线点)
- uva 270 Lining Up(暴力+ 几何)
- uva 270 Lining Up(暴力)
- hdoj--1432--Lining Up(暴力模拟)
- poj 1118 Lining Up (暴力)
- UVA 270 Lining Up 共线点 暴力
- poj 1118 Lining Up(暴力+数学)
- POJ1118,Lining Up,暴力过的,hash什么的只能仰慕
- uva 270 Lining Up(暴力或极角排序)
- uva - 270 - Lining Up(枚举、排序)
- UVA - 270 Lining Up(贪心)
- sql语句中select top n与oracle的rownum与mysql的limit用法
- MYSQL入门学习之二十四:MySQL逻辑模块组成
- 定义两个整型指针,分别用malloc、calloc对其分配空间保存3个元素,malloc分配的空间用memset清零,随机对数组进行赋值随机范围1-3,赋值后用memcmp比较两个数组。如果相同打印G
- 探索性数据分析week4
- 有关wireshark抓包工具出现The NPF driver isn't running. You may have trouble capturing or listing interfaces
- uva270 - Lining Up(暴力)
- 有一段文本,将文本中的所有单词,存放到一个字符指针数组中(要求每个单词内存恰好)
- MYSQL入门学习之二十五:MySQL各模块工作配合
- NoSQL数据库的基础知识
- Map集合遍历
- 用汇编的眼光看C++(开篇)
- MYSQL入门学习之二十六:MySQL存储引擎简介 之 MyISAM
- 20140730纪念一下CSDN博客开通
- SASS在HTML5移动应用开发中的应用