第十二届蓝桥杯B组题目及题解

== 蓝桥杯B组(java 或者C)==

填空题

前两道填空题就不说了

在这里插入图片描述
这道题大多数人应该都是卡到了精度问题 double比较大小小于一定的精度我们就认为已经相等了直接上代码

#include <iostream>
#include <cstring>
#include <algorithm>
#include "cmath"

using namespace std;

typedef pair<double, double> PII;



PII l[200000];

int main(){
   
   
   int n = 0; 
   for (int x1 = 0; x1 < 20; x1 ++ )
        for (int y1 = 0; y1 < 21; y1 ++ )
            for (int x2 = 0; x2 < 20; x2 ++ )
                for (int y2 = 0; y2 < 21; y2 ++ )
                    if (x1 != x2)               //去掉斜率不存在的情况
                    {
   
                        double k = (double)(y2 - y1) / (x2 - x1);
                        double b = y1 - k * x1;
                        l[n ++ ] = {
   k, b};
                    }
    sort (l, l + n);
    int res = 1;
    for (int i = 1; i < n; i ++){
   
        if(fabs(l[i].first - l[i - 1].first) > 1e-8 || fabs(l[i].second - l[i - 1].second) > 1e-8)
           res ++;
    }
    
    cout << res + 20 <<endl;
    答案 :40257
}

在这里插入图片描述
这一道题考察的就是大数的公约数

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;

int main()
{
   
    LL n;
    cin >> n;
    vector<LL> d;
    for (LL i = 1; i * i <= n; i 
  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值