蓝桥杯第四场双周赛(1~6)

1、水题

2、模拟题,写个函数即可

#define pb push_back
#define x first
#define y second 
#define int long long
#define endl '\n'
const LL maxn = 4e05+7;
const LL N = 5e05+10;
const LL mod = 1e09+7;
const int inf = 0x3f3f;
const LL llinf = 5e18;typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
LL gcd(LL a, LL b){return b > 0 ? gcd(b , a % b) : a;
}LL lcm(LL a , LL b){return a / gcd(a , b) * b;
}
int n , m;
int a[N];
void init(int n){for(int i = 0 ; i <= n ; i ++){a[i] = 0;}
}
int qc(int a, int b , int c){return (a + b + c)/2;
}
int alg(int a , int b , int c){int cc = qc(a , b , c);return (cc * (cc - a) * (cc - b) * (cc - c));
}
void solve() 
{int a , b , c;cin >> a >> b >> c;if(a + b <= c || a + c <= b || b + c <= a){cout << -1;}elsecout << alg(a , b , c);
}            
signed main() 
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);int t=1;
//	cin>>t;while(t--){solve();}return 0;
}

3、模拟题,找规律,第一行和最后一行只有两个数,其余行都是三个数。

     第一行特殊处理,其余行:  (x + 1) / 3 + 1 就是当前所在行rx - ((r - 1) * 3 - 1)就是所在行第s个数 , 每行第一个数是r - 1, 因此所在列就是r - 1 + s。

        

#include <iostream>
using namespace std;
int main()
{long long n , m;cin >> n >> m;for(int i = 0 ; i < m ; i ++){long long x;cin >> x;if(x <= 1){cout << 1 << " " << x + 1 << endl;}else{long long r = (x + 1) / 3 + 1;long long st = x - ((r - 1) * 3 - 1);long long dc = r - 1 + st;cout << r << " " << dc << endl;}}return 0;
}

4、考虑找到x^a , y^b , z^c的所有可能取值,取值上界应该为10^{12} * 10^5 = 10^{17}。由于2^{64}>10^{18},因此每个肯定不超过64种取值。用三重循环找到所有  x^a + y^b + z^c的所有取值,复杂度为O(64^3)。注意x^a*x<inf判断可能会爆long long , 所以在判断是否到达上界需要用x^a < inf/x。用数组或者set去存每种取值,然后从小到大排序。按照题目条件对每个询问搜索即可(二分/暴力)。整体复杂度O(q * 64^3)/O(q*log(64^3))

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second 
#define endl '\n'
const LL maxn = 4e05+7;
const LL N = 5e05+10;
const LL mod = 1e09+7;
const int inf = 0x3f3f;
const LL llinf = 2e18;
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
LL gcd(LL a, LL b){return b > 0 ? gcd(b , a % b) : a;
}LL lcm(LL a , LL b){return a / gcd(a , b) * b;
}
int n , m;
LL a , b , c;
set<LL>st;
void solve() 
{cin >> a >> b >> c;vector<LL>aa , bb , cc;aa.pb(1);bb.pb(1);cc.pb(1);LL x = 1;while(a != 1 && x < llinf / a){x *= a;aa.pb(x);}LL y = 1;while(b != 1 && y < llinf / b){y *= b;bb.pb(y);}LL z = 1;while(c != 1 && z < llinf / c){z *= c;cc.pb(z);}for(int i = 0 ; i < aa.size() ; i ++){for(int j = 0 ; j < bb.size() ; j ++){for(int z = 0 ; z < cc.size() ; z ++){st.insert(aa[i] + bb[j] + cc[z]);}}}int m;cin >> m;for(int i = 0 ; i < m ; i ++){LL que;cin >> que;auto it = st.upper_bound(que);while(*it - que == 1){que = *it;it = st.upper_bound(que);}cout << que + 1 << " " << (*it - que - 1) << endl;}
}            
int main() 
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);int t=1;
//	cin>>t;while(t--){solve();}return 0;
}

5、 方法很多,大体思路为将类型一样的宝石放到一起,将他们的作用区间进行合并,然后对整个数组进行区间修改。

        区间合并:将所有区间按照左端点排序,遍历区间,若当前左端点与前一个区间右端点有重合部分,则将他们合并成一个区间,否则将前一个区间存下来,当前区间为一个新的区间。

        区间修改:差分/树状数组/线段树。

        

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second 
#define endl '\n'
const LL maxn = 4e05+7;
const LL N = 5e05+10;
const LL mod = 1e09+7;
const int inf = 0x3f3f;
const LL llinf = 5e18;
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
LL gcd(LL a, LL b){return b > 0 ? gcd(b , a % b) : a;
}LL lcm(LL a , LL b){return a / gcd(a , b) * b;
}
int n , m;
int a[N];
void init(int n){for(int i = 0 ; i <= n ; i ++){a[i] = 0;}
}
struct BIT{//Binary indexed Tree(树状数组)int n;vector<int> tr;BIT(int n) : n(n) , tr(n + 1 , 0){}int lowbit(int x){return x & -x;}void modify(int x , int modify_number){for(int i = x ; i <= n ; i += lowbit(i)){tr[i] += modify_number;}}void modify(int l , int r , int modify_number){modify(l , modify_number);modify(r + 1 , -modify_number);}int query(int x){int res = 0;for(int i = x ; i ;  i -= lowbit(i))res += tr[i];return res;}int query(int x , int y){return query(y) - query(x);}
};
void solve() 
{int n , m , q;cin >> n >> m >> q;vector<int>len(m + 5);for(int i = 1 ; i <= m ; i++){cin >> len[i];}BIT bit(n);vector<pair<int,int>>que;for(int i = 0 ; i < q ; i ++){int x , y;cin >> x >> y;que.pb({x , y});}sort(que.begin() , que.end());int r = 0 , pos = 0;for(int i = 0 ;i < q ; i ++){if(que[i].x != pos){pos = que[i].x;r = 0;}bit.modify( max(r + 1, que[i].y) , min(que[i].y + len[pos] - 1 , n) , 1);r = min(que[i].y + len[pos] - 1 , n);}for(int i = 1 ; i <= n ; i ++){cout << bit.query(i)<<" ";}
}            
int main() 
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);int t=1;
//	cin>>t;while(t--){solve();}return 0;
}

6、删除区间求中位数比较困难。相反,增加数求区间中位数就是一道对顶堆的板子题了。因此考虑逆着做题,先将所有会飘走的气球放弃,将其余气球加入对顶堆。然后再从后往前依次添加气球,维护对顶堆找答案即可(对顶堆网上一大堆模板)。

        

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second 
#define endl '\n'
const LL maxn = 4e05+7;
const LL N = 5e05+10;
const LL mod = 1e09+7;
const int inf = 0x3f3f;
const LL llinf = 5e18;
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
LL gcd(LL a, LL b){return b > 0 ? gcd(b , a % b) : a;
}LL lcm(LL a , LL b){return a / gcd(a , b) * b;
}
int n , m;
int a[N];
void init(int n){for(int i = 0 ; i <= n ; i ++){a[i] = 0;}
}
void solve() 
{cin >> n;for(int i = 1 ; i <= n ; i ++){cin >> a[i];}cin >> m;double ans[m + 5];int que[m + 5];int vis[n + 5];memset(vis,0,sizeof vis);for(int i = 1 ; i <= m ; i ++){cin >> que[i];vis[que[i]] = 1;}for(int i = 1 ;i <= n ; i ++){if(!vis[i]){ma.push(a[i]);}}while(ma.size() > mi.size()){mi.push(ma.top());ma.pop();}for(int i = m ; i > 0 ; i --){if((mi.size() + ma.size()) % 2 == 0){//偶数int x = mi.top();int y = ma.top();ans[i] = (double)(1.0 * x + y) / 2;}else{double x = mi.top();ans[i] = (double)(1.0 * x);}int yy = mi.top();if(a[que[i]] > yy){mi.push(a[que[i]]);}else{ma.push(a[que[i]]);}while(mi.size() > ma.size() + 1){ma.push(mi.top());mi.pop();}while(ma.size() > mi.size()){mi.push(ma.top());ma.pop();}}for(int i = 1 ; i <= m ; i++){printf("%.1f " , ans[i]);}
}            
int main() 
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);int t=1;
//	cin>>t;while(t--){solve();}return 0;
}

        

7、边数据较小,网络流问题。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/219082.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

flex布局实战之自动填充剩余

案例目标 文字部分自适应并且居中 图中是一个弹窗&#xff0c;我现在使用flex的布局来实现&#xff0c;标题和关闭按钮。因为是uni-app,所以标签是view 。你可以自行替换为 代码 <view class"popup-box"><view class"title"><view class&…

积跬步至千里 || 为循环添加进度条

有时候&#xff0c;我们的Python程序需要运行较长时间&#xff0c;原因是一些环节占用时间太长&#xff08;如for循环&#xff09;。如果我们要观察那些占用时间任务的执行进度&#xff0c;那么有一个进度条能实时的显示任务进度情况的话&#xff0c;将会非常方便。而tqdm库就是…

C语言—二维数组

一、二维数组的创建 int arr[3][4];char arr[3][5];double arr[2][4]; 数组创建&#xff1a;“[ ]”中要给一个常量&#xff0c;不能使用变量 二、二维数组的初始化 int arr[3][4]{1,2,3,4};int arr[3][4]{{1,2},{4,5}};int arr[][4]{{2,3},{4,5}}; 前面的为行&#xff0c…

JavaScript之DOM操作

第一章 API介绍 ​API是一种事先定义好的函数&#xff0c;用来提供应用程序与开发人员基于某软件或硬件得以访问的一组例程&#xff0c;而又无需访问源码&#xff0c;或理解内部工作机制的细节。 ​Web API接口&#xff1a;浏览器提供的一系列操作浏览器功能和页面元素的API(BO…

dat文件转换成excel教程

dat文件存在于很多的日用场合&#xff0c;为了更好的去进行办公使用&#xff0c;很多的用户都会将dat文件转换成excel&#xff0c;但是不知道怎么操作的却很多&#xff0c;下面来看看教程吧。 dat文件转换成excel&#xff1a; 1、首先打开excel&#xff0c;然后点击上面的“数…

2023-3年CSDN创作纪念日

机缘 今天开开心心出门去上班&#xff0c;就收到了一个csdn私信&#xff0c;打开一看说是给我惊喜来着&#xff0c;我心想csdn还能给惊喜&#xff1f;以为是有什么奖品或者周边之类的&#xff0c;结果什么也没有&#xff0c;打开就是一份信&#x1f602;。 也挺不错的&#xf…

与Windows 10更新大同小异!一步一步教你如何更新Windows 11

如果你想让你的Windows 11设备获得最佳性能&#xff0c;那么定期更新是至关重要的。即使是最好的电脑如果不更新也会受到影响&#xff0c;因为更新会应用软件调整&#xff0c;帮助你的设备更快、更平稳地运行。它还提高了安全性&#xff0c;意味着你可以从Microsoft的最新功能中…

YOLOv5小目标检测层

目录 一、原理 二、yaml配置文件 一、原理 小目标检测层,就是增加一个检测头,增加一层锚框,用来检测输入图像中像素较小的目标 二、yaml配置文件 # YOLOv5 🚀 by Ultralytics, GPL-3.0 license# Parameters nc: 3 # number of classes depth_multiple: 0.33 # model…

RocketMq 队列(MessageQueue)

RocketMq是阿里出品&#xff08;基于MetaQ&#xff09;的开源中间件&#xff0c;已捐赠给Apache基金会并成为Apache的顶级项目。基于java语言实现&#xff0c;十万级数据吞吐量&#xff0c;ms级处理速度&#xff0c;分布式架构&#xff0c;功能强大&#xff0c;扩展性强。 官方…

笔记:pycharm当有多个plt.show()时候,只显示第一个plt.show()

import matplotlib.pyplot as plt import numpy as np# 创建数据 x np.linspace(0, 10, 100) y1 np.sin(x) y2 np.cos(x) y3 np.tan(x) y4 np.exp(x)# 创建一个2x2的子图网格 # fig plt.figure() fig,((ax1, ax2), (ax3, ax4)) plt.subplots(nrows2, ncols2, figsize(8,…

Kibana部署

服务器 安装软件主机名IP地址系统版本配置KibanaElk10.3.145.14centos7.5.18042核4G软件版本&#xff1a;nginx-1.14.2、kibana-7.13.2-linux-x86_64.tar.gz 1. 安装配置Kibana &#xff08;1&#xff09;安装 [rootelk ~]# tar zxf kibana-7.13.2-linux-x86_64.tar.gz -C…

Day02嵌入式---按键控灯

一、简单介绍 按键控制灯开关是一种常见的嵌入式系统示例项目&#xff0c;它通常用于演示嵌入式系统的基本控制能力。该项目由一个或多个LED和一个按键组成。通过按下按键&#xff0c;可以控制LED的开关状态&#xff0c;从而实现灯的亮灭控制。 二、查看功能手册 2.1 查看硬件…