class Node{ public double k; public double b; public Node(double k, double b) { this.k = k; this.b = b; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Node node = (Node) o; return Double.compare(node.k, k) == 0 && Double.compare(node.b, b) == 0; } @Override public int hashCode() { return Objects.hash(k, b); } } public class SenvenB { public static void main(String[] args){ Set<Node> set = new HashSet<>(); for(int i = 0;i < 20;i++){ for(int j = 0;j < 21;j++){ for(int r = 0;r < 20;r++){ for(int l = 0;l < 21;l++){ if(r - i == 0){ continue; } double k = (l-j)*1.0/(r-i); double b = (j*r-l*i)*(1.0) / (r-i); if(k == -0.0){ k = 0.0; } if(b == -0.0){ b = 0.0; } set.add(new Node(k,b)); } } } } System.out.println(set.size()+20); } }
蓝桥杯之直线题解
最新推荐文章于 2022-04-05 14:37:45 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)