当前位置: 首页 > news >正文

天津建站模板企业文化宣传

天津建站模板,企业文化宣传,西安的网站建设,wordpress 近期文章 代码这是一道有关于滑动窗口的题目 题目链接:https://codeforces.com/gym/104354/attachments 对于这道题可以用两种方法(实则是一种) 1-小根堆中存每两个元素的差值,然后用窗口去滑每一个子区间,遍历找出最小答案 #inc…

这是一道有关于滑动窗口的题目

题目链接:https://codeforces.com/gym/104354/attachments

 对于这道题可以用两种方法(实则是一种)

1-小根堆中存每两个元素的差值,然后用窗口去滑每一个子区间,遍历找出最小答案

#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define PII pair<int,int>
#define fi first
#define se second
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
const int N =5e5+10; 
int a[N];
priority_queue<PII,vector<PII>,greater<PII>> q;void solve()
{int n,k;cin>>n>>k;for(int i=1;i<=n;i++)cin>>a[i];sort(a+1,a+1+n);for(int i=2;i<=k;i++) q.push({a[i]-a[i-1],i});int ans=1e18;for(int i=k;i<=n;i++){q.push({a[i]-a[i-1],i});while(!q.empty()&&i-k+1>q.top().se)//如果i-k>q.top.se了说明当前的窗口已经不包含这两个元素了{q.pop();}ans = min(ans,q.top().fi*(a[i]-a[i-k+1]));}cout<<ans<<endl;
}
signed main()
{IOSint T=1;
//	cin>>T;while(T--) solve(); return 0;
} 

2-小根堆中用于存放当前包含a[i]和a[i-1]的窗口,然后遍历每一个差值,找出包含这两个元素的窗口的max的最小值

#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define PII pair<int,int>
#define fi first
#define se second
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
const int N =5e5+10; 
int a[N];
priority_queue<PII,vector<PII>,greater<PII>> q;void solve()
{int n,k;cin>>n>>k;for(int i=1;i<=n;i++){cin>>a[i];}sort(a+1,a+1+n);PII mx; mx.fi = a[k]-a[1];mx.se =1;int mi = a[2]-a[1];int ans = mi*mx.fi;q.push(mx);for(int i=2;i<=n;i++){int l = q.top().se;while(!q.empty()&&l+k-1<i){q.pop();l = q.top().se;}mx = q.top();mi = a[i]-a[i-1];ans = min(ans,mx.fi*mi);int x;if(i+k-1<=n) x = a[i+k-1]-a[i];else x = a[n]-a[n-k+1];q.push({x,i});}cout<<ans<<endl;
}
signed main()
{IOSint T=1;
//	cin>>T;while(T--) solve(); return 0;
} 

http://www.dtcms.com/a/599315.html

相关文章:

  • 济南网站建设流程江苏网站建设渠道
  • 石家庄网站开发公司python如何做网站
  • 长春网站优化哪家好wordpress 4.7.1下载
  • 十堰网站建设培训学校网站的绝对路径怎么做
  • 西安设计网站的公司泉州网站建设服务
  • 网站标题关键词描述wordpress横幅
  • 360移动建站服务营销案例100例
  • 做网站策划营销推广网络营销以什么为基础
  • 免费购物网站程序公司网站费用计入什么科目
  • 简单公司网站医院设计机构
  • 下载宝硬盘做网站怎么创业呢白手起家
  • 企业网站建设哪家公司好wordpress显示注册人数
  • UNet改进(45):融合Group Convolution与Hierarchical Feature Fusion的图像分割模型
  • 中国机械加工网站官网洛夕网站建设
  • 企业网站 html模板室内设计平面图纸
  • 网页制作与网站建设实战大全pdfseo优化关键词排名
  • 中文域名转码网站桐乡建设规划局网站
  • 建立网站要准备多少钱怎样在微信上制作自己的链接
  • cpanel wordpress是什么深圳网站关键字优化
  • 同一个空间可以做两个网站么泉州关键词优化排名
  • 网站淘宝客 难做wordpress模板 论坛
  • 做素食香料哪个网站买网站建设的目的和作用
  • 陕西省建设部官方网站筑巢网站后台管理系统
  • 网站建设 电话creo二次开发
  • 网站源代码免费下载自己可以制作微信小程序吗
  • 完整的无锁队列实现含多线程竞争规避策略
  • 重庆任务盟网站建设wordpress 4.5.4
  • 咸宁网站建设报价企业应该如何进行网站建设
  • 进入职场第四课—产出
  • 企业响应网站网站产品详情用哪个软件做的