[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
在平面直角坐标系中,两点可以确定一条直线。如果有多点在一条直线上, 那么这些点中任意两点确定的直线是同一条。
给定平面上 2 × 3 个整点(x,y)∣0≤x<2,0≤y<3,x∈Z,y∈Z {(x, y)|0 ≤ x < 2, 0 ≤ y < 3, x ∈ Z,
y ∈ Z},即横坐标 是 0到 1 (包含 0 和 1) 之间的整数、纵坐标是 0 到 2 (包含 0 和 2) 之间的整数 的点。这些点一共确定了 11
条不同的直线。
给定平面上 20×21 个整点 (x,y)∣0≤x<20,0≤y<21,x∈Z,y∈Z{(x, y)|0 ≤ x < 20, 0 ≤ y < 21, x ∈
Z, y ∈ Z},即横 坐标是 0到 19 (包含 0 和 19) 之间的整数、纵坐标是 0到 20 (包含 0和 20) 之 间的整数的点。
请问这些点一共确定了多少条不同的直线。
思路:通过斜率k与b可以确定一条直线,先得k,再通过y=kx+b得到b。map映射模板,让确定的值为1。
#include<bits/stdc++.h> using namespace std; struct Point{ double x, y;
}p[25*25];//存下每一个点 map<pair<double,double> ,int> mp;//存斜率k和截距b int main(){ int
cnt = 0; for(int i = 0;i < 20;i++){ for(int j = 0;j < 21;j++){ p[cnt].x = i;
p[cnt++].y = j; } } int ans = 20 + 21; for(int i = 0;i < cnt;i++){ for(int j =
0;j < cnt;j++){ //两点的直线与坐标轴平行或共点 if(p[i].x == p[j].x || p[i].y == p[j].y)
continue; //斜率和截距 double k = (p[j].y - p[i].y) / (p[j].x - p[i].x); double b =
(p[j].x * p[i].y - p[j].y * p[i].x) / (p[j].x - p[i].x); if(mp[{k,b}] == 0){
mp[{k,b}] = 1; ans++; } } } cout << ans << endl; return 0; }