POJ 3668 Game of Lines
来源:互联网 发布:大隅级两栖攻击舰 数据 编辑:程序博客网 时间:2024/05/02 02:38
POJ 3668 Game of Lines
传送门
题意:给你n个点,两点之间有一条直线,求有多少条互不平行的直线。
水题一道,直接暴力求出所有直线的斜率,去重即可。
有坑,存在不存在斜率的情况,判断一下就行了。
去重我采用了一个排序,在暴力跑一边,时间有点长,47MS。
代码如下:
#include<cstdio>#include<algorithm>using namespace std;long long num[20200],x[205],y[205],n,ans,tot,xl;//xl是斜率的简写int main(){ scanf("%lld",&n); for(int i=1;i<=n;i++) scanf("%lld%lld",&x[i],&y[i]); for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) { if(x[i]-x[j]!=0) xl=((y[j]-y[i])*10000000.0/((x[j]-x[i])*1.0)); //整数化,防止精度问题,当时直接乘的1e8,结果过了,运气好啊..... else xl=2100000000;//不存在斜率时随便赋一个值即可 num[++tot]=xl; } sort(num+1,num+tot+1); for(int i=1;i<=tot;i++) if(num[i]!=num[i+1])//去重 ans++; printf("%lld\n",ans); return 0;}
0 0
- POJ 3668 Game of Lines
- POJ 3668 Game of Lines
- POJ 3668 Game of Lines
- POJ 3668 Game of Lines
- poj 3668 Game of Lines
- POJ 3668 Game of Lines 笔记
- POJ 2668 Game of Lines
- POJ 3668 Game of Lines(n点最多有多少不平行直线)
- 连线游戏Game of Lines
- POJ 3215 Median of Lines 英文少
- POJ 2084 Game of Connections
- poj 2084 Game of Connections
- POJ 2084 Game of Connections
- POJ-2084-Game of Connections
- poj 2084 Game of Connections
- poj 2084 Game of Connections
- [POJ] 2084 -> Game of Connections
- POJ 2084 Game of Connections
- 函数指针做为参数的例子
- String,StringBuffer与StringBuilder的区别
- Android中ArrayList的使用注意事项以及效率的比较
- SVN 的使用
- 聚类算法和分类算法总结
- POJ 3668 Game of Lines
- 随机化算法
- android学习心得:error:Warning: Activity not started, its current task has been brought to the front
- linux下scp使用
- 水光学中的超越数e
- 这个python用法太优雅,一定要转
- 对I2C总线时序的一点理解以及ACK和NACK(NAK)
- Emacs 快键
- 页面不显示原因