平行直线

题意:给出一些点,这些点两两相连成一条直线,问最多能连成多少条直线。

思路:暴力出奇迹!!记得当时比赛做这道题的时候一直依赖于板子,结果却限制了自己的思路,这得改。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的更多相关文章

  1. 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 ...

  2. HDU3465 树状数组逆序数

    Life is a Line Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)T ...

  3. Coursera Robotics系列课心得

    Robotics Perception Professor Kostas and Jianbo Shi week 1: camera model 凸透镜成像原理:凸透镜焦点与焦距是固定的,这是物理性质 ...

  4. 东大OJ-一元三次方程解的个数

    1043: Fixed Point 时间限制: 5 Sec  内存限制: 128 MB 提交: 26  解决: 5 [提交][状态][讨论版] 题目描述 In mathematics, a fixed ...

  5. 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 ...

  6. [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 ...

  7. 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 ...

  8. 最长上升子序列(N*log(N))hdu1025

    (HDU1025) Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  9. 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 ...

随机推荐

  1. addSubview和insertSubview 区别

     子视图是以栈的方式存放的. 每次addsubview时都是在最后面添加. 每次在addsubview前和addsubview后可以看看[self.view.subViews count]: 你看看你 ...

  2. 站点过滤器Filter

    --过滤器使用已经非常久了,今天遇到了一个小问题.也就想顺便写一个关于过滤器的博文.记录一下自己使用的感受. 实际上,Filter与Servlet及其相似,差别仅仅是FIlter的doFilter() ...

  3. Java设计模式菜鸟系列(一)策略模式建模与实现

    转载请注明出处:http://blog.csdn.net/lhy_ycu/article/details/39721563 今天開始咱们来谈谈Java设计模式. 这里会结合uml图形来解说,有对uml ...

  4. session失效,使用ajax请求数据被拦截,此时正常的处理逻辑是跳到登录界面,而不是界面没有变化(java推断是否是ajax请求)

    在登录过滤器中.推断请求是ajax请求还是超链接或者地址栏变化的请求 if (httpServletReq.getHeader("x-requested-with") != nul ...

  5. jQuery--编辑表格

    表格操作是我们常常遇到的,还记得刚開始学习牛腩新闻公布系统时.跟着视频进行表格的一些基本操作.而对它的原理与概念全然不懂,不过跟着老师的操作而进行操作. 通过这次学习,对表格的操作有了进一步的了解与掌 ...

  6. 树莓派玩耍笔记1 -- 开箱 &amp; 安装系统以及简单配置

    零.前言 树莓派是什么? 吃的么? 呵呵,假设您连这个还不知道,真是out 了. 麻烦出门左拐.百度去(或者,看看官网去?),算了.还是粘贴一些大家都知道的树莓派百科吧: 树莓派由注冊于英国的慈善组织 ...

  7. Linux下的ssh实验环境搭建与管理

    实验环境[size=10.5000pt]1:网桥模式[size=10.5000pt]2:安装好vmtoos[size=10.5000pt]3:安装好yum[size=10.5000pt]4:安装好ss ...

  8. Android 信息提示——Toast方式

    Toast用于向用户显示一些帮助/提示.一下列举了5中样式. 一.默认的效果(显示在屏幕的底部) 代码: Toast.makeText(getApplicationContext(), "默 ...

  9. JSTL判断list的size()大小,以及choose(相当于if else作用)

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ tag ...

  10. 杂项:LDAP

    ylbtech-杂项:LDAP 1.返回顶部 1. LDAP是轻量目录访问协议,英文全称是Lightweight Directory Access Protocol,一般都简称为LDAP.它是基于X. ...