在平面直角坐标系中,两点可以确定一条直线
如果有多点在一条直线上,那么这些点中任意两点确定的直线是同一条
给定平面上2x3个整点((x,y)l0<x<20y<3,xezyeZ
即横坐标是0到1(包含0和1)之间的整数、纵坐标是0到2(包含0和2)之间的整数的点这些点一共确定了11条不同的直线。
给定平面上20x21个整点{(x,y)l0x<20,0y<21,XEZyEZ
即横坐标是0到19(包含0和19)之间的整数、纵坐标是0到20(包含0和20)之间的整数的点请问这些点一共确定了多少条不同的直线。
#include<iostream>
using namespace std;
#include<vector>
class Point
{
public:
Point()
{
}
Point(int x, int y)
{
this->m_x = x;
this->m_y = y;
}
int m_x;
int m_y;
};
class Line
{
public:
Line()
{
}
Line(int coefficient_x, int coefficient_y, int constant)
{
this->m_coefficient_x = coefficient_x;
this->m_coefficient_y = coefficient_y;
this->m_constant = constant;
}
int m_coefficient_x;
int m_coefficient_y;
int m_constant;
bool operator==(Line& l)
{
if (this->m_coefficient_x == l.m_coefficient_x && this->m_coefficient_y == l.m_coefficient_y && this->m_constant == l.m_constant)
{
return true;
}
else
{
return false;
}
}
bool operator!=(Line& l)
{
if (this->m_coefficient_x == l.m_coefficient_x && this->m_coefficient_y == l.m_coefficient_y && this->m_constant == l.m_constant)
{
return false;
}
else
{
return true;
}
}
};
void CreatePoint(vector<Point> &v_Point,int x,int y)
{
for (int i = 1; i < x; ++i)
{
for (int j = 1; j < y; ++j)
{
Point p(i, j);
v_Point.push_back(p);
}
}
v_Point.resize(v_Point.size());
}
void CreateLine(vector<Line> v_Line,vector<Point> v_Point)
{
for (vector<Point>::iterator it = v_Point.begin(); it != v_Point.end(); ++it)
{
for (vector<Point>::iterator it_2 = v_Point.begin(); it_2 != v_Point.end(); ++it_2)
{
int temp_coefficient_x = (*it).m_y - (*it_2).m_y;
int temp_coefficient_y = (*it_2).m_x - (*it).m_x;
int temp_constant = (*it).m_x * (*it_2).m_y - (*it_2).m_x * (*it).m_y;
Line l(temp_coefficient_x, temp_coefficient_y, temp_constant);
v_Line.push_back(l);
}
}
}
void Erase_repetition(vector<Line>& v_Line)
{
for (vector<Line>::iterator it = v_Line.begin(); it != v_Line.end()-1; ++it)
{
for (vector<Line>::iterator it_2 = it+1; it_2 != v_Line.end(); ++it_2)
{
if ((*it) == (*it_2))
{
v_Line.erase(it_2);
}
}
}
v_Line.resize(v_Line.size());
}
void Output_result_Line_vector(vector<Line> &v_Line)
{
cout << "The number of line:_____\b\b\b\b\b" << v_Line.size() << endl;
}
int main()
{
vector<Point> v_Point;
vector<Line> v_Line;
int x, y;
cout << "Enter the value of X axis:_____\b\b\b\b\b";
cin >> x;
--x;
cout << "Enter the value of Y axis:_____\b\b\b\b\b";
cin >> y;
--y;
CreatePoint(v_Point,x, y);
CreateLine(v_Line, v_Point);
Erase_repetition(v_Line);
Output_result_Line_vector(v_Line);
return 0;
}
出现以下错误:
不是很理解这个错误。