题意:给出几个点的位置,问一条直线最多能连过几个点。

只要枚举每两个点组成的直线,然后找直线上的点数,更新最大值即可。

我这样做过于暴力,2.7s让人心惊肉跳。。。应该还能继续剪枝的,同一直线找过之后就可以剪掉了。

代码:

 /*
* Author: illuz <iilluzen@gmail.com>
* Blog: http://blog.csdn.net/hcbbt
* File: uva270.cpp
* Lauguage: C/C++
* Create Date: 2013-08-25 10:54:55
* Descripton: UVA 270 Lining Up, greed, enumeration, brute force
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <utility>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repu(i, a, b) for (int i = (a); i < (b); i++)
#define repf(i, a, b) for (int i = (a); i <= (b); i++)
#define repd(i, a, b) for (int i = (a); i >= (b); i--)
#define swap(a, b) {int t = a; a = b; b = t;}
#define mc(a) memset(a, 0, sizeof(a))
#define ms(a, i) memset(a, i, sizeof(a))
#define sqr(x) ((x) * (x))
#define FI(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
typedef long long LL;
typedef unsigned long long ULL; /****** TEMPLATE ENDS ******/ const int MAXN = 710;
int cas, n;
char str[100];
pair<int, int> p[MAXN]; int main() {
scanf("%d\n", &cas);
rep(c, cas) {
n = 0;
while (gets(str) && strlen(str)) {
// puts(str);
sscanf(str, "%d%d", &p[n].first, &p[n].second);
n++;
}
int Max = 1, sum;
rep(i, n) repu(j, i + 1, n) {
sum = 2;
int tx = p[i].first - p[j].first, ty = p[i].second - p[j].second;
rep(k, n) {
if (k == i || k == j) continue;
if ((p[k].first - p[i].first) * ty == (p[k].second - p[i].second) * tx)
sum++;
}
if (sum > Max)
Max = sum;
}
if (c) printf("\n");
printf("%d\n", Max);
}
return 0;
}

UVA 270 Lining Up 共线点 暴力的更多相关文章

  1. UVA 270 Lining Up (几何 判断共线点)

     Lining Up  ``How am I ever going to solve this problem?" said the pilot. Indeed, the pilot was ...

  2. UVA.129 Krypton Factor (搜索+暴力)

    UVA.129 Krypton Factor (搜索+暴力) 题意分析 搜索的策略是:优先找长串,若长串不合法,则回溯,继续找到合法串,直到找到所求合法串的编号,输出即可. 注意的地方就是合法串的判断 ...

  3. UVA.10986 Fractions Again (经典暴力)

    UVA.10986 Fractions Again (经典暴力) 题意分析 同样只枚举1个,根据条件算出另外一个. 代码总览 #include <iostream> #include &l ...

  4. UVa 270 & POJ 1118 - Lining Up

    题目大意:给一些点,找出一条直线使尽可能多的点在这条直线上,求这条直线上点的个数. 以每一个点为原点进行枚举,求其它点的斜率,斜率相同则说明在一条直线上.对斜率排序,找出斜率连续相等的最大长度. #i ...

  5. uva 10825 - Anagram and Multiplication(暴力)

    题目链接:uva 10825 - Anagram and Multiplication 题目大意:给出m和n,要求找一个m位的n进制数,要求说该数乘以2~m中的随意一个数的结果是原先数各个位上数值的一 ...

  6. UVa 11210 Chinese Mahjong (暴力,递归寻找)

    题意:这个题意.有点麻烦,就是说给定13张牌,让你求能“听”的牌.(具体的见原题) 原题链接: https://uva.onlinejudge.org/index.php?option=com_onl ...

  7. UVa 11059 最大乘积 java 暴力破解

    题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...

  8. UVa 817 According to Bartjens (暴力,DFS)

    题意:给出一个数字组成的字符串,然后在字符串内添加三种运算符号 * + - ,要求输出所有添加运算符并运算后结果等于2000的式子. 所有数字不能有前导0, 且式子必须是合法的. 析:这个题很明显的暴 ...

  9. UVA 10976 分数拆分【暴力】

    题目链接:https://vjudge.net/contest/210334#problem/C 题目大意: It is easy to see that for every fraction in ...

随机推荐

  1. 64位系统未注册"MSDAORA.1"提供程序

    原因:如错误,64位系统未注册"MSDAORA.1"提供程序 解决:在IIS应用程序池中找到自己的网站,打开高级设置,设置“启用32位应用程序”为“True”即可. 另外还有其他解 ...

  2. w3wp.exe CPU过百问题

    w3wp.exe CPU过百问题 最近发布在windows  server2012  IIS8.0上的一个WebAPI项目,才几十个人在线,CPU就会出现过百情况,并且CPU一旦过百应用程序池就自动暂 ...

  3. Struts2 中action之间的跳转(分享)

    例如从你的login.action到register.action  有两种实现方式 1. 设置type="redirect" <package  name="st ...

  4. Flex LinkButton鼠标划过出现下划线

    在LinkButton中 textDecoration属性设置label的是否有下划线装饰,属性值分为"none","underline" 代码如下------ ...

  5. 【水一发next_permutation】poj 1146——ID Codesm

    来源:点击打开链接 求字典序下一位,没有直接输出没有.全排列函数秒水过. #include <iostream> #include <algorithm> #include & ...

  6. HDU 2087 剪花布条 KMP入门

    Problem Description 一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条.计算一下能从花布条中尽可能剪出几块小饰条来呢?   Input ...

  7. srm 534

    250 Description 给你一个1*n的棋盘.两人轮流行动,每一个人能够把"o"向右移动到空格子.或者跨越连续两个"o"到空格子. 一个"o& ...

  8. Android中GPS简介及其应用

    GPS是Global Positioning System(全球定位系统)的简称,它的作用就是为全球的物体提供定位功能.GPS定位是一门高新技术,但对于Android程序员来说,开发GPS功能的应用程 ...

  9. authorization 元素(ASP.NET 设置架构)

    authorization 元素(ASP.NET 设置架构) 其他版本 1(共 1)对本文的评价是有帮助 - 评价此主题 [本文档仅供预览,在以后的发行版中可能会发生更改.包含的空白主题用作占位符.] ...

  10. 学习MVC遇到的问题

    修改电脑上的DNS配置: Opendns 首选DNS服务器和备用DNS服务器分别设置为208.67.222.222和208.67.220.220 google的8.8.8.8 首选DNS服务器和备用D ...