第十二届蓝桥杯省赛B组

在这里插入图片描述
答案:40257

				k = (y2-y1)/(x2-x1);
           		b = (y1*x2-y2*x1)/(x2-x1);
import java.util.Set;
import java.util.TreeSet;

public class Main{
    public static void main(String[] args){
        int res = 20+21; //斜率不存在和平行于x轴的情况
        Set<Node> set = new TreeSet<>();
        Node[] nodes = new Node[20*25];
        int cnt = 0;
        for(int i=0;i<=19;i++){
            for(int j=0;j<=20;j++){
                nodes[cnt++] = new Node(1.0*i,1.0*j);
            }
        }
        for(int i=0;i<cnt;i++){
            for(int j=i+1;j<cnt;j++){
                double x1 = nodes[i].x;
                double y1 = nodes[i].y;
                double x2 = nodes[j].x;
                double y2 = nodes[j].y;
                if(x1==x2||y1==y2) continue;
                double k = (y2-y1)/(x2-x1);
                double b = (y1*x2-y2*x1)/(x2-x1);
                set.add(new Node(k,b));
            }
        }
        System.out.println(res+set.size());
    }
}
class Node implements Comparable<Node>{
    double x,y;

    public Node(double x, double y) {
        this.x = x;
        this.y = y;
    }



    @Override
    public int compareTo(Node o) {
        if(Double.compare(this.x,o.x)!=0) return Double.compare(this.x,o.x);
        return Double.compare(this.y,o.y);
    }
}

在这里插入图片描述
答案:2430
思路:试除法获取2021041820210418的所有约数 然后枚举约数,并且将该约数分解为两数乘积,获得三个数乘积的形式,将三个数排序,如果没有出现过此种排列,那么根据三个数是否相等,累加答案

import java.util.Arrays;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        Set<Long> set = new TreeSet<>();//储存所有的约数
        for(long i=1;i<=n/i;i++){
            if(n%i==0) {
                set.add(i);
                set.add(n/i);
            }
        }
        Set<Node> res = new TreeSet<>();//记录答案
        Object[] objects = set.toArray();
        int ans = 0;
        for(int i=0;i<objects.length;i++){
            Long a = (Long)objects[i];
            for(long j=1;j<=a/j;j++){//把a分解为两个约数的乘积
                if(a%j==0){
                    long[] arr = new long[3];
                    arr[0] = j;
                    arr[1] = a/j;
                    arr[2] = n/a;
                    Arrays.sort(arr,0,3);
                    if(res.contains(new Node(arr[0],arr[1],arr[2]))) continue;
                    if(arr[0]==arr[1]&&arr[1]==arr[2]){
                        ans += 1;
                    }else if(arr[0]==arr[1]||arr[1]==arr[2]){
                        ans += 3;
                    }else{
                        ans += 6;
                    }
                    res.add(new Node(arr[0],arr[1],arr[2]));
                }
            }
        }
        System.out.println(ans);
    }
}
class Node implements Comparable<Node>{
    long a,b,c;

    public Node(long a, long b, long c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    @Override
    public int compareTo(Node o) {
        if(Long.compare(this.a,o.a)!=0) return Long.compare(this.a,o.a);
        if(Long.compare(this.b,o.b)!=0) return Long.compare(this.b,o.b);
        return Long.compare(this.c,o.c);
    }
}

在这里插入图片描述
思路参考https://zhuanlan.zhihu.com/p/37895166

原文地址:https://www.cnblogs.com/fxzemmm/p/14847904.html