平行直线

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

思路:暴力出奇迹!!记得当时比赛做这道题的时候一直依赖于板子,结果却限制了自己的思路,这得改。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. 技术架构model

  2. 【Unity】用Shader编程实现3D红心

    有些形状,即使没有3D美术设计师提供模型,也能够用代码生成. 对于想保持原创性不想借用他人模型的独立开发人员来说,这无非是一个非常重要的途径. 今天献给大家的是用Shader编程实现的一颗红心,寄托下 ...

  3. android 获取屏幕的高度和宽度、获取控件在屏幕中的位置、获取屏幕中控件的高度和宽度

    (一)获取屏幕的高度和宽度 有两种方法: 方法1: WindowManager wm = (WindowManager) getContext().getSystemService(Context.W ...

  4. JavaScript Patterns 2.1 Writing Maintainable Code

    Revisiting the code after some time has passed requires: • Time to relearn and understand the proble ...

  5. touch事件的分发机制

    作者:谢昆 一段伪代码反应整个touch事件的分发 public boolean dispatchTouchEvent(MotionEvent event) { boolean consume = f ...

  6. bzoj3771

    http://www.lydsy.com/JudgeOnline/problem.php?id=3771 生成函数... 其实就是多项式乘法...lrj书上有一个通俗的解释... 然后就是这个样子,我 ...

  7. codevs3287货车运输(最小生成树+LCA)

    3287 货车运输 2013年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond     题目描述 Description A 国有 ...

  8. Canvas和SVG的基础知识,以及两者的区别(小白)

    首先我们来说一下Canvas是什么,它有什么作用以及它的知识点. Canvas是<HTML5>的新标签,它通常用于通过脚本(也就是JavaScript)来绘制图像.但是它本身并没有绘制能力 ...

  9. JavaScript正则表达式(一)-常用方法

    公司之前有个胖女孩说你竟然会正则? 其实正则没那么难:今天我们说说他常用的几个API. 在讲方法之前, 我们先对正则表达式做一个基本的了解: 1.正则表达式定义使用单个字符串来描述.匹配一系列符合某个 ...

  10. SQLYog 快捷键

    SQLYog常用快捷键 Ctrl+M     创建一个新的连接Ctrl+N     使用当前设置新建连接Ctrl+F4    断开当前连接 对象浏览器F5         刷新对象浏览器(默认)Ctr ...