Aizu - 1379 Parallel Lines
题意:给出一些点,这些点两两相连成一条直线,问最多能连成多少条直线。
思路:暴力出奇迹!!记得当时比赛做这道题的时候一直依赖于板子,结果却限制了自己的思路,这得改。dfs直接暴力,但是需要将已经走过的点标记一下,用一个循环跳过已经标记的点减少dfs次数,不然得不出正确的结果,因为会出现如下的连线结果(左图),而正确的连线方式应该如右图。

代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <cstring>
#include <queue>
#define INF 0x3f3f3f3f
#define MIN(a,b) a<b ? a : b
#define MAX(a,b) a>b ? a : b//确实要比C++自带的max函数要快
#define FRE() freopen("in.txt","r",stdin)
using namespace std;
const int maxn = ;
const int MOD = 1e9 + ;
typedef long long ll;
typedef pair<int, int> P;
struct Point {
int x,y;
} p[maxn];
struct Line {
int x,y;
} l[maxn];
int m,ans,cnt,vis[maxn]; int upDate() {//遍历任意两条边之间是否平行,更新最大的结果
int res = ;
for(int i = ; i<cnt; i++)
for(int j = i+; j<cnt; j++) {
if(l[i].x*l[j].y == l[i].y*l[j].x){//注意有斜率不存在情况,所以要对等式做一下变形
res++;
}
}
return res;
} void dfs(int now) {
while(vis[now])//减少dfs次数,同样也是避免出现之前说的情况
now++;
if(now == m) {
ans = MAX(upDate(),ans);
return;
}
vis[now] = ;
for(int i = ; i<m; i++) {
if(!vis[i] && cnt != i) {
l[cnt].x = p[now].x - p[i].x;
l[cnt].y = p[now].y - p[i].y;
vis[i] = ;
cnt++;
dfs(now+);//枚举的是每种连接方式下的点的个数
cnt--;
vis[i] = ;
}
}
vis[now] = ;
return;
} int main() {
memset(vis,,sizeof(vis));
scanf("%d",&m);
for(int i = ; i<m; i++) {
scanf("%d%d",&p[i].x,&p[i].y);
}
ans = ;
cnt = ;
dfs();
printf("%d\n",ans);
return ;
}
Aizu - 1379 Parallel Lines的更多相关文章
- Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem H. Parallel Worlds 计算几何
Problem H. Parallel Worlds 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c7 ...
- HDU3465 树状数组逆序数
Life is a Line Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)T ...
- Coursera Robotics系列课心得
Robotics Perception Professor Kostas and Jianbo Shi week 1: camera model 凸透镜成像原理:凸透镜焦点与焦距是固定的,这是物理性质 ...
- 东大OJ-一元三次方程解的个数
1043: Fixed Point 时间限制: 5 Sec 内存限制: 128 MB 提交: 26 解决: 5 [提交][状态][讨论版] 题目描述 In mathematics, a fixed ...
- Logistic Regression Vs Decision Trees Vs SVM: Part I
Classification is one of the major problems that we solve while working on standard business problem ...
- [ACM] hdu 1025 Constructing Roads In JGShining's Kingdom (最长递增子序列,lower_bound使用)
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- HDU 1025 Constructing Roads In JGShining's Kingdom(二维LIS)
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- 最长上升子序列(N*log(N))hdu1025
(HDU1025) Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory ...
- hdu--(1025)Constructing Roads In JGShining's Kingdom(dp/LIS+二分)
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
随机推荐
- word2vec 中的数学原理具体解释(六)若干源代码细节
word2vec 是 Google 于 2013 年开源推出的一个用于获取 word vector 的工具包,它简单.高效,因此引起了非常多人的关注.因为 word2vec 的作者 Tomas M ...
- Hadoop Yarn(一)—— 单机伪分布式环境安装
HamaWhite(QQ:530422429)原创作品,转载请注明出处:http://write.blog.csdn.net/postedit/40556267. 本文是依据Hadoop官网安装教程写 ...
- shell中获取时间,作为文件夹格式
近期写了一个小程序,须要用到时间.遍历作为文件夹的一部分 #!/bin/bash for i in {1..30} do date=`date +%Y/%m/%d -d " $i days ...
- YTU 2760: 字符串---首字母变大写
2760: 字符串---首字母变大写 时间限制: 1 Sec 内存限制: 128 MB 提交: 343 解决: 136 题目描述 输入一行英文句子,将每个单词的第一个字母改成大写字母. 输入 一个 ...
- influx测试——单条读性能很差,大约400条/s,批量写性能很高,7万条/s,总体说来适合IOT数据批量存,根据tag查和过滤场景,按照时间顺序返回
测试准备 需要将InfluxDB的源码放入 go/src/github.com/influxdata 目录 单写测试代码(write1.go): package main import ( " ...
- [Swift通天遁地]三、手势与图表-(9)制作五彩缤纷的气泡图表
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- 个人作业 - Alpha 项目测试
写在前面 课程链接:https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass2 作业要求:https://edu.cnblogs.com ...
- 动态规划DP入门
百度百科↓ 动态规划(dynamic programming)是运筹学的一个分支,是求解决策过程(decision process)最优化的数学方法.20世纪50年代初美国数学家R.E.Bellman ...
- JavaScript 计时器
在JavaScript中,我们可以在设定的时间间隔之后来执行代码,而不是在函数被调用后立即执行.计时器类型:一次性计时器:仅在指定的延迟时间之后触发一次.间隔性触发计时器:每隔一定的时间间隔就触发一次 ...
- html表单代码演示
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...