POJ3668Game of Lines(数学问题)
来源:互联网 发布:java 排列组合算法 编辑:程序博客网 时间:2024/05/24 01:35
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 00 01 1
Sample Output
4
Source
题目大意:给你n个点的x1,y1,然后问你有多少个不互相平行的直线
解题思路:这道题是个数学问题,运用到了斜率这个概念,要想让两条直线不互相平行,最重要的条件就是直线的斜率不相同,于是用map取存一下不同斜率出现了几次,输出的时候size()统计一下就好了,同时要注意一下斜率不存在即两点的y值相减为0的情况,这里我用ans取计算,然后暴力完判一下ans即可,比较水WA的原因就是放进map的时候要double一下不然很尴尬
#include<iostream> #include<cstdio> #include<stdio.h> #include<cstring> #include<cstdio> #include<climits> #include<cmath> #include<vector> #include <bitset> #include<algorithm> #include <queue> #include<map> using namespace std;struct point{int x, y;}p[205], pp;int i, j, n;map<double, int> XL;int main(){cin >> n;long long int ans = 0;for (i = 1; i <= n; i++){cin >> p[i].x >> p[i].y;}ans = 0;for (i = 1; i <= n; i++){for (j = i + 1; j <= n; j++){pp.x = p[i].x - p[j].x;pp.y = p[i].y - p[j].y;if (pp.y == 0){ans++;}else{XL[(double)pp.x / pp.y]++;}}}if (ans == 0){cout <<XL.size()<< endl;}else{cout << XL.size() + 1 << endl;}}
- POJ3668Game of Lines(数学问题)
- Lines of Containers
- Hottest lines of romantic moives
- POJ 3668 Game of Lines
- POJ 3668 Game of Lines
- POJ 2668 Game of Lines
- APPEND LINES OF 的用法
- UVA 12652 Lines of Containers
- linux: Count Lines of Code
- POJ 3668 Game of Lines
- POJ 3668 Game of Lines
- 连线游戏Game of Lines
- poj 3668 Game of Lines
- SGU - 135 - Drawing Lines (简单数学!)
- Modifying a set of lines directly
- ffmpeg: the mother of all command lines
- Impact of cpu cache lines验证
- paste utilitiy -- merge lines of files
- Ubuntu VLC没有声音解决
- Linux十个命令补全技巧(下)
- HTML基本知识点——Table表格
- HTML5第五课时,标签选择器
- 1064. 朋友数(20)
- POJ3668Game of Lines(数学问题)
- 【Linux网络编程】组播代码
- 基于C++的简单24点小游戏
- git版本管理命令行整理
- 使用PhotoView的问题解决
- 动态规划--计算字符串距离
- 从头到尾彻底理解KMP
- HDU 5667 Sequence 【矩阵快速幂】
- Jenkins安装及使用(CentOS6.5)