POJ3668 Game of Lines
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6791 | Accepted: 2523 |
Description
Farmer John has challenged Bessie to the following game: FJ has a board with dots marked at N (2 ≤ N ≤ 200) distinct lattice points. Dot i has the integer coordinates Xi and Yi (-1,000 ≤ Xi ≤ 1,000; -1,000 ≤ Yi ≤ 1,000).
Bessie can score a point in the game by picking two of the dots and drawing a straight line between them; however, she is not allowed to draw a line if she has already drawn another line that is parallel to that line. Bessie would like to know her chances of winning, so she has asked you to help find the maximum score she can obtain.
Input
* Line 1: A single integer: N
* Lines 2..N+1: Line i+1 describes lattice point i with two space-separated integers: Xi and Yi.
Output
* Line 1: A single integer representing the maximal number of lines Bessie can draw, no two of which are parallel.
Sample Input
4
-1 1
-2 0
0 0
1 1
Sample Output
4
Source
计算每条线的斜率,然后统计不同斜率的个数就可以。
又陷入了一WA就是好几次的窘境啊……
先是RE,反映半天原来是数组开小了,然后各种WA,于是看了评论区,发现要调精度到1e-8
……
/**/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const double eps=1e-;
const int mxn=;
double x[mxn],y[mxn];
int n;
double k[mxn*];
int cnt;
int main(){
scanf("%d",&n);
int i,j;
for(i=;i<=n;i++)scanf("%lf%lf",&x[i],&y[i]);
for(i=;i<n;i++)
for(j=i+;j<=n;j++){
if(x[i]==x[j])k[++cnt]=1e15;
else k[++cnt]=(double)(y[i]-y[j])/(x[i]-x[j]);
}
sort(k+,k+cnt+);
int ans=;
ans++;//一定可以画至少一条
for(i=;i<cnt;i++){
if(fabs(k[i]-k[i+])>eps)ans++;
}
cout<<ans;
return ;
}
POJ3668 Game of Lines的更多相关文章
- extracting lines bases a list using awk
extracting lines bases a list using awk awk 'NR==FNR{a[$1]=$0; next}($1 in a){print a[$1]"\n&qu ...
- Enum:Game of Lines(POJ 3668)
画直线 题目大意:给定一些点集,要你找两点之间的连线不平行的有多少条 数据量比较少,直接暴力枚举,然后放到set查找即可 #include <iostream> #include < ...
- 我的常用mixin 之 lines
/** * 最多显示 $lineCount 行 * lines * * example: * @include lines; * @include lines(3); */ @mixin lines( ...
- uva 1471 defence lines——yhx
After the last war devastated your country, you - as the king of the land of Ardenia - decided it wa ...
- POJ 1269 Intersecting Lines --计算几何
题意: 二维平面,给两条线段,判断形成的直线是否重合,或是相交于一点,或是不相交. 解法: 简单几何. 重合: 叉积为0,且一条线段的一个端点到另一条直线的距离为0 不相交: 不满足重合的情况下叉积为 ...
- POJ 1269 Intersecting Lines【判断直线相交】
题意:给两条直线,判断相交,重合或者平行 思路:判断重合可以用叉积,平行用斜率,其他情况即为相交. 求交点: 这里也用到叉积的原理.假设交点为p0(x0,y0).则有: (p1-p0)X(p2-p0) ...
- [CareerCup] 13.1 Print Last K Lines 打印最后K行
13.1 Write a method to print the last K lines of an input file using C++. 这道题让我们用C++来打印一个输入文本的最后K行,最 ...
- Codeforces 593B Anton and Lines
LINK time limit per test 1 second memory limit per test 256 megabytes input standard input output st ...
- 简单几何(直线位置) POJ 1269 Intersecting Lines
题目传送门 题意:判断两条直线的位置关系,共线或平行或相交 分析:先判断平行还是共线,最后就是相交.平行用叉积判断向量,共线的话也用叉积判断点,相交求交点 /********************* ...
随机推荐
- 【Kaggle】泰坦尼克号
引言 Kaggle官方网站 这是泰坦尼克号事件的基本介绍: 我们需要做的就是通过给出的数据集,通过对特征值的分析以及运用机器学习模型,分析什么样的人最可能存活,并给出对测试集合的预测. 对于Kaggl ...
- 为什么C++编译器不能支持对模板的分离式编译
首先,一个编译单元(translation unit)是指一个.cpp文件以及它所#include的所有.h文件,.h文件里的代码将会被扩展到包含它的.cpp文件里,然后编译器编译该.cpp文件为一个 ...
- python-7面向对象高级编程
1-给类动态增加方法 class Student(object): pass def set_score(self, score): self.score = score Student.set_sc ...
- 笔记-redis深入学习-1
笔记-redis深入学习-1 redis的基本使用已经会了,但存储和读取只是数据库系统最基础的功能: 数据库系统还得为可靠实现这两者提供一系列保证: 数据.操作备份和恢复,主要是持久化: 高可用:主要 ...
- gcc常用命令
1简介 2简单编译 2.1预处理 2.2编译为汇编代码(Compilation) 2.3汇编(Assembly) 2.4连接(Linking) 3多个程序文件的编译 4检错 5库文件连接 5.1编译成 ...
- python ranndom模块及生成验证码
python的random模块用于生成随机数,下面介绍一下random模块的常用方法: 取随机小数: 数学计算 random.random() 用于生成一个0-1的随机浮点数 0<=n<1 ...
- C17K:Lying Island
链接 题意: 有n个人,每个人可能会说: 第x个人是好人/坏人 如果第x个人是好人/坏人,则第y个人是好人/坏人 思路: 状压dp,首先每个人所说的人只能是他前面10个人,所以对于第i个人记录下,他前 ...
- 2.栅格的类中同时设置col-md-* col-sm-*的作用
1.一般设定成这样的话,在小屏幕上会堆叠在一起 <div class="row"> <div class="col-md-4 ">COL ...
- laravel5.5配置信息
目录 1 环境配置 1.1 检索环境配置 1.2 确定当前环境 2 访问配置值 3 配置缓存 4 维护模式 配置文件在config目录下,为了便于不同人员的开发,我们可以使用不同的.env文件来配置各 ...
- centso下如何解压RAR文件
tar -xvf rarlinux-3.9.3.tar.gz cd rar make 看见下面这些信息就是安装成功了 mkdir -p /usr/local/bin mkdir -p /usr/l ...