第 36 场 蓝桥·算法挑战赛·百校联赛---赛后复盘

2. 平台优惠

本题是一个排序题。

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n,ans;
int a[N], b[N];
int main()
{
  cin >> n;
  for(int i = 0; i < n; i ++ ) cin >> a[i];
  sort(a,a+n);
  for(int i = 0; i < n; i ++ ) b[i] = a[n - 1 - i];
  for(int i = 0; i < n; i ++ ) 
    if(i % 3 != 2)
      ans += b[i];
  cout << ans;
  // 请在此输入您的代码
  return 0;
}

3. 圆上移动

考察取模。

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n,m,x,ans;
int a[N];
int main()
{
  cin >> n >> m >> x;
  for(int i = 1; i <= n; i ++ ) {
    cin >> a[i];
    x = x + a[i];
    if(x % m == 0)ans++;
  }
  cout << ans;
  // 请在此输入您的代码
  return 0;
}

4. 受限交换

考察的逆序对数,太难了。

5. 危险任务

贪心算法。

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;
int a,b,c,ans;
int main()
{
  cin >> a >> b >> c;
  while(a!=b)
  {
    ans++;
    if((a+2)%c==0||a+1==b) a++;
    else a+=2;
  }
  cout<<ans;
  // 请在此输入您的代码
  return 0;
}

6. 质数雷达

这题考察的是质数筛,会就不难,不会就难。学过忘了。

相关推荐
wuminyu8 小时前
Virtual Thread重投递至ForkJoinPool任务队列过程解析
java·linux·c语言·jvm·c++
垆边人似月.8 小时前
华为题:污染水域
算法
All for pursuit.9 小时前
【回溯-6】79.单词搜索
数据结构·c++·算法·leetcode
ZhangJun959 小时前
Mobike 共享单车分析项目
人工智能·python·算法·kmeans·聚类·knn
Navigator_Z9 小时前
LeetCode //C - 1281. Subtract the Product and Sum of Digits of an Integer
c语言·算法·leetcode
薛定e的猫咪9 小时前
(AISTATS 2023)BaCaDI 逐章阅读
人工智能·深度学习·算法·机器学习
Benny_Tang9 小时前
AT_arc180_d [ARC180D] Division into 3 题解
数据结构·c++·算法
殷色玫瑰10 小时前
C++ STL:stack、queue、priority_queue 与容器适配器详解
java·开发语言·数据结构·c++·算法·visualstudio
努力努力再努力wz10 小时前
【CUDA入门系列】CUDA编程实战:设备选择、显存管理、Kernel、Stream 与 Event 全流程梳理
开发语言·c++
Evand J10 小时前
【电机滤波例程1】PMSM永磁同步电机转速与位置估计,MATLAB程序:标准无迹卡尔曼滤波、模型说明与仿真验证
算法·matlab·电机·ekf·负载·卡尔曼滤波