lanqiao 1449 直线
This commit is contained in:
23
12lanqiao/test3.cpp
Normal file
23
12lanqiao/test3.cpp
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
// lanqiao 1449 直线
|
||||||
|
#include<bits/stdc++.h>
|
||||||
|
using namespace std;
|
||||||
|
int main(){
|
||||||
|
set<pair<double, double>> s; // 使用set对{k, b}数据对去重
|
||||||
|
// 枚举第一个坐标点
|
||||||
|
for(int x1 = 0; x1 < 20; x1++){
|
||||||
|
for(int y1 = 0; y1 <21; y1++){
|
||||||
|
// 枚举第二个坐标点
|
||||||
|
for(int x2 = x1+1; x2 < 20; x2++){
|
||||||
|
for(int y2 = 0; y2 < 21; y2++){
|
||||||
|
double k = (double)(y2-y1)/(x2-x1);
|
||||||
|
// double b = (double)(y1 - ((y2-y1)/(x2-x1)) * x1);
|
||||||
|
// 上面这个式子先算除法再算乘法,存在精度误差,最好先通分一下
|
||||||
|
double b = (double)(x2*y1 - x1*y2)/(x2-x1);
|
||||||
|
s.insert({k, b});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << s.size() + 20 << endl; // +20代表与x轴垂直的直线
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user