首页 技术 正文
技术 2022年11月10日
0 收藏 863 点赞 3,159 浏览 1411 个字

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

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

我这样做过于暴力,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;
}
上一篇: Sicily-1006
下一篇: 用typedef声明类型
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,086
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,561
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,410
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,183
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,820
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,903