蓝桥云课小白入门赛题解

3.数学奇才

可以进行n次变相反数的操作,那就全变正数就好了。

#include <cmath>
#include <iostream>
using namespace std;

typedef long long LL;

int n;

int main()
{
  // 请在此输入您的代码
  cin >> n;
  LL res = 0;
  for(int i = 0; i < n; i ++ )
  {
    LL x; cin >> x;
    res += abs(x);
  }
  cout << res;
  return 0;
}

4.你不干?有的是帕鲁干

分类讨论,平方差 = (x - y) * (x + y) 然后又要是连续的正奇数,肯定就是(x + 2 - x) * (x + 2 + x),所以化简就可以得第一个奇数为x = (y - 4) / 4,显然,y一定要大于8才可以。

#include <cstring>
#include <iostream>
using namespace std;

typedef long long LL;

int main()
{
  // 请在此输入您的代码
  int T;
  cin >> T;

  while(T -- )
  {
    LL x; cin >> x;
    if(x < 8) puts("No");
    else
    {
      LL t = x - 4;
      if(t % 4 || t / 4 % 2) puts("No");
      else
      {
        t /= 4;
        puts("Yes");
        cout << t << ' ' << t + 2 << endl;
      }
    }
  }  
  return 0;
}

5.等腰三角形

模拟,贪心

设第三边为x, 另外两边为b, 0 < x < 2 * b,所以这个第三边满足条件的,从小到大枚举找答案就完事了。

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
const int N = 2e5 + 10;

int n;
int a[N], b[N];
vector<int> c;
set<int> ss;
map<int, int> cnt_a;
map<int, int> cnt_b;

int main()
{
  // 请在此输入您的代码
  cin >> n;
  for(int i = 0; i < n; i ++ )
  {
    cin >> a[i];
    cnt_a[a[i]] ++;
  }
  for(int i = 0; i < n; i ++ )
  {
    cin >> b[i];
    cnt_b[b[i]] ++;
    ss.insert(b[i]);
  }

  for(auto x : ss)
    c.push_back(x);

  LL res = 0;
  int j = 0;
  for(auto [x, y] : cnt_a)
  {
    int t = y;
    while(j < c.size())
    {
      if(c[j] >= 2 * x) break;
      int d = min(t, cnt_b[c[j]]);
      res += d;
      t -= d;
      cnt_b[c[j]] -= d;
      if(!cnt_b[c[j]]) j ++;
      if(!t) break;
    }
  }
  cout << res;

  return 0;
}

6.计算方程

二分找答案,因为有个根号在,所以在用实数比较时, 要开一个边界值为eps,其它就是带公式了。

#include <cmath>
#include <iostream>
using namespace std;

typedef long long LL;
const double eps = 1e-8;

bool check(LL x, int k, int m)
{
  double a = sqrt(x);
  LL b = log(x) / log(k);
  return a + b - m >= eps;
}

int main()
{
  // 请在此输入您的代码
  int T;
  cin >> T;
  while(T -- )
  {
    int k, m;
    cin >> k >> m;
    
    LL l = 1, r = 1e18;
    while(l < r)
    {
      LL mid = l + r >> 1;
      if(check(mid, k, m)) r = mid;
      else l = mid + 1;
    }
    cout << r << endl;
  }
  return 0;
}
  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值