POJ 3668 Game of Lines
来源:互联网 发布:炽热狙击网络连接失败 编辑:程序博客网 时间:2024/05/23 01:08
给定 n 个点,每个点都可以和另一个点相连,问你共有多少种不同斜率的直线。
细节:
1.用j=i+1减少循环次数,避免重复。
2.求斜率用y2-y1/x2-x1,考虑x2==x1斜率不存在的情况
呃,当时觉得用set比较好用,但是一直写错
set方法:
int main() { while (scanf ("%d", &n) == 1) { sets.clear(); for (int i = 0; i < n; ++i) { scanf ("%d %d", &x[i], &y[i]); } for (int i = 0; i < n; ++i) for (int j = i+1; j < n; ++j) if (x[i] == x[j]) { sets.insert (inf); } else { sets.insert ( (y[i]-y[j]) *1.0/ (x[i]*1.0-x[j]*1.0) ); } printf ("%d\n", sets.size() ); } return 0;}
一般方式
利用排序,方便去重
struct point { double x,y;} P[205];double xl[25000];int main() { int N; while (~scanf ("%d",&N) ) { for (int i=0; i<N; ++i) { scanf ("%lf%lf",&P[i].x,&P[i].y); } int L=0,ans=1/***/; for (int i=0; i<N-1; i++) { for (int j=i+1/***/; j<N; ++j) { if (P[i].x==P[j].x) {xl[L++]=INF;}/*!!*/ else { xl[L++]= (P[j].y-P[i].y) / (P[j].x-P[i].x); } } } sort (xl,xl+L); for (int i=1; i<L; ++i) { if (xl[i]!=xl[i-1]) { ans++; } } printf ("%d\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
- 什么是P问题、NP问题和NPC问题
- muduo : Reactor(EventLoop Poller Channel)
- HDU 3544 Alice's Game (不平等博弈)*
- tjut 2845
- JSP中的EL表达式
- POJ 3668 Game of Lines
- waitUntilDone YES/ NO
- 2dx-lua Other Linker Flags 设置成 -ObjC 真机编译报错"_GCControllerDidDisconnectNotification"
- 创建线程的两种方法
- hibernate 多对1
- 华为OJ——合并表记录
- JDK1.7中的ThreadPoolExecutor源码剖析
- HDFS的Java接口
- 转] Hibernate不能自动建表解决办法(hibernate.hbm2ddl.auto) (tables doesn't exist)