第十二届蓝桥杯省赛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

### 关于第十二届蓝桥杯BC++试题及解答 对于第十二届蓝桥杯BC++的相关题目解析资料,虽然目前提供的引用并未直接提及该具体年份的内容[^1],但可以根据以往比的特点以及常见题型进行分析。 #### 常见题型概述 蓝桥杯通常涉及以下几个方面的知识点: - **基础算法**:如排序、查找等基本操作。 - **数据结构**:栈、队列、链表的应用场景。 - **动态规划**:解决最优子结构性问题的有效方法。 - **字符串处理**:模式匹配、字符统计等问题。 以下是基于过往经验整理的一个典型例题及其解决方案: #### 示例题目与解答 假设某道题目如下所示: > 输入两个正整数a,b (0<a<b<1e9),求它们的最大公约数。 ##### 解决方案 可以采用欧几里得算法来高效计算最大公约数。 ```cpp #include <iostream> using namespace std; // 定义函数gcd用于计算最大公约数 int gcd(int a, int b){ while(b != 0){ int temp = a % b; a = b; b = temp; } return a; } int main(){ int a, b; cin >> a >> b; cout << "The GCD of " << a << " and " << b << " is: " << gcd(a, b) << endl; return 0; } ``` 此代码片段展示了如何通过循环迭代的方式实现辗转相除法以找到两数之间的最大公约数[^2]。 #### 进一步学习资源建议 为了更好地准备此类事,推荐查阅历年真题并尝试独立完成每一道题目。此外还可以关注官方发布的最新通知技术文档获取更多指导信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值