[BZOJ1610][Usaco2008 Feb]Line连线游戏
2015-09-11 12:11
549 查看
传送门
http://www.lydsy.com/JudgeOnline/problem.php?id=1610题目大意
给n个点,有多少种斜率题解
直接求斜率,然后排序判断即可,注意不存在斜率的情况var z:array[0..40005]of double; x,y:array[0..205]of longint; i,j,k:longint; n,len,ans:longint; procedure sort(l,r:longint); var i,j:longint; a,b:real; begin i:=l; j:=r; a:=z[(l+r) div 2]; repeat while z[i]<a do inc(i); while a<z[j] do dec(j); if not(i>j) then begin b:=z[i]; z[i]:=z[j]; z[j]:=b; inc(i); dec(j); end; until i>j; if l<j then sort(l,j); if i<r then sort(i,r); end; begin readln(n); len:=0; for i:=1 to n do readln(x[i],y[i]); for i:=1 to n do for j:=i+1 to n do begin inc(len); if x[i]=x[j] then z[len]:=maxlongint else z[len]:=(y[i]-y[j])/(x[i]-x[j]); end; sort(1,len); {z[i]} z[0]:=-2; ans:=0; for i:=1 to len do if z[i]<>z[i-1] then inc(ans); writeln(ans); end.
相关文章推荐
- [LeetCode] Perfect Squares 完全平方数
- 利用CSS三角形实现的冒泡框
- JS计算滚动条的宽度
- 详解CSS选择器、优先级与匹配原理
- jquery的ajax()函数传值中文乱码解决方法介绍
- RichTextEx一款通过HTML标签控制文字样式的富文本控件
- React 编码
- css3布局-左右两栏固定宽度,中间栏优先加载
- js检测页面是否在框架内,防止页面被其他框架引用
- CSS布局-两边固定,中间自适应
- JavaScript处理解析JSON数据过程详解
- Knockout应用开发指南 第六章:加载或保存JSON数据
- CSS权重的问题:选择器权重值的计算
- jquery进阶
- php输出js到前端
- ListView和GridView利用pull-to-rerfesh 实现下拉刷新和上拉加载更多
- Remove Nth Node From End of List
- jquery Autocomplete 实现自动补全(四)解决jquery 高版本不支持browser方法
- Js获取当前日期时间及其它操作
- seaJS入门