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 ...
随机推荐
- VBS调用Windows API函数
Demon's Blog 忘记了,喜欢一个人的感觉 Demon's Blog » 程序设计 » VBS调用Windows API函数 « 用VBS修改Windows用户密码 在VB中创建和使用 ...
- 百度开放云java+tomcat部署web项目-小皇帝詹姆斯
加入部署 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/diss ...
- LeetCode 929. Unique Email Addresses (独特的电子邮件地址)
题目标签:String 题目说明 有两个规则针对于 local name. 所以先把local name 和 domain name 分开. 两个规则是: rule 1:'.' 会被去除. (利用re ...
- 暴力解hdu4930Fighting the Landlords
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> us ...
- ubuntu拨号上网以及路由设置
1.宽带拨号 配置宽带连接信息:pppoeconf 拨号:pon dsl-provider 断开连接:poff dsl-provider 查看拨号日志:plog 2.路由设置 以下为rc.local文 ...
- hdoj-1214-圆桌会议【逆序数】
圆桌会议 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissi ...
- linux下.a/.so/.la目标库区别
在linux平台上编译时,常会遇到目标库的疑问,有静态库也有动态库,单个理解都不太难,但是对复杂的工程而言,一旦混合到一起去,对整个工程的理解和调用,将会造成很大困扰,本文就汇总这几种常见编译结果文件 ...
- MSP430 WDT
MSP430 WDT 有两种模式:1,看门狗 2,定时器 我们这次只用定时器模式,注意有两个决定定时时间的地方:1,时钟源选择 2,间隔时间选择 时钟源可以为:SMCLK 或者 ACLK 时间间隔 ...
- Coursera Algorithms Programming Assignment 4: 8 Puzzle (100分)
题目原文:http://coursera.cs.princeton.edu/algs4/assignments/8puzzle.html 题目要求:设计一个程序解决8 puzzle问题以及该问题的推广 ...
- 设计模式 |备忘录模式(memento)
定义: 在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象之外保存这个状态.这样以后就可以将该对象恢复到原先保存的状态. 结构:(书中图,侵删) Originator:需要备份的类(写在便签上 ...