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

模板网站建设代理商微信引流被加软件

模板网站建设代理商,微信引流被加软件,Wordpress搜索指定页面内容,做网站赚钱嘛CF1692E Binary Deque 题解题目链接字面描述题面翻译题目描述输入格式输出格式样例 #1样例输入 #1样例输出 #1提示思路代码实现题目 链接 https://www.luogu.com.cn/problem/CF1692E 字面描述 题面翻译 有多组数据。 每组数据给出 nnn 个数,每个数为 000 或 1…

CF1692E Binary Deque 题解

  • 题目
    • 链接
    • 字面描述
      • 题面翻译
      • 题目描述
      • 输入格式
      • 输出格式
      • 样例 #1
        • 样例输入 #1
        • 样例输出 #1
      • 提示
  • 思路
  • 代码实现

题目

链接

https://www.luogu.com.cn/problem/CF1692E

字面描述

题面翻译

有多组数据。

每组数据给出 nnn 个数,每个数为 000111 。你可以选择从两边删数,求至少删几个数才可以使剩下的数总和为 sss

如果不能达到 sss ,则输出 −1-11

题目描述

Slavic has an array of length $ n $ consisting only of zeroes and ones. In one operation, he removes either the first or the last element of the array.

What is the minimum number of operations Slavic has to perform such that the total sum of the array is equal to $ s $ after performing all the operations? In case the sum $ s $ can’t be obtained after any amount of operations, you should output -1.

输入格式

The first line contains a single integer $ t $ ( $ 1 \leq t \leq 10^4 $ ) — the number of test cases.

The first line of each test case contains two integers $ n $ and $ s $ ( $ 1 \leq n, s \leq 2 \cdot 10^5 $ ) — the length of the array and the needed sum of elements.

The second line of each test case contains $ n $ integers $ a_i $ ( $ 0 \leq a_i \leq 1 $ ) — the elements of the array.

It is guaranteed that the sum of $ n $ over all test cases doesn’t exceed $ 2 \cdot 10^5 $ .

输出格式

For each test case, output a single integer — the minimum amount of operations required to have the total sum of the array equal to $ s $ , or -1 if obtaining an array with sum $ s $ isn’t possible.

样例 #1

样例输入 #1

7
3 1
1 0 0
3 1
1 1 0
9 3
0 1 0 1 1 1 0 0 1
6 4
1 1 1 1 1 1
5 1
0 0 1 1 0
16 2
1 1 0 0 1 0 0 1 1 0 0 0 0 0 1 1
6 3
1 0 1 0 0 0

样例输出 #1

0
1
3
2
2
7
-1

提示

In the first test case, the sum of the whole array is $ 1 $ from the beginning, so we don’t have to make any operations.

In the second test case, the sum of the array is $ 2 $ and we want it to be equal to $ 1 $ , so we should remove the first element. The array turns into $ [1, 0] $ , which has a sum equal to $ 1 $ .

In the third test case, the sum of the array is $ 5 $ and we need it to be $ 3 $ . We can obtain such a sum by removing the first two elements and the last element, doing a total of three operations. The array turns into $ [0, 1, 1, 1, 0, 0] $ , which has a sum equal to $ 3 $ .

思路

因为题目要求为从原数组2边删最少元素,使得总元素和为sss,

设初始数组元素总和为cntcntcnt

cnt<scnt<scnt<s,直接输出−1-11

否则程序继续

这道题十分友善
∵允许从数组2边删数\because允许从数组2边删数允许从数组2边删数
∴最终序列内部顺序相比于原数组不变\therefore 最终序列内部顺序相比于原数组不变最终序列内部顺序相比于原数组不变

一个很好思考的想法油然而生,

  1. 对原数组进行前缀和预处理
  2. 枚举i=[1,n]i=[1,n]i=[1,n]
    • 二分第一个f[op]−f[i]≥sf[op]-f[i]≥sf[op]f[i]sopopop
    • 算位数取最小值

时间复杂度: ο(n⋅log2(n))\omicron (n·log2(n))ο(nlog2(n))

代码实现

#include<bits/stdc++.h>
using namespace std;const int maxn=2e5+10;
const int inf=2e9;
int t,n,op,x,ans=inf;
int f[maxn];
int main(){scanf("%d",&t);while(t--){ans=inf;scanf("%d%d",&n,&op);for(int i=1;i<=n;i++){scanf("%d",&x);f[i]=f[i-1]+x;}if(f[n]<op){printf("-1\n");continue; }for(int i=1;i<=n;i++){if(f[i]<op)continue;int p=lower_bound(f,f+n+1,f[i]-op)-f;ans=min(ans,p+n-i);}printf("%d\n",ans);}return 0;
}
http://www.tj-hxxt.cn/news/48014.html

相关文章:

  • 如何接做网站编程的生意中央网站seo
  • 红酒 专业 网站建设企业推广文案范文
  • 房山网站建设聚合搜索引擎入口
  • 网站建设优化一体如何让百度搜索排名靠前
  • 清河做网站报价关键路径
  • 做牛津布面料在哪个网站找客户网站优化及推广
  • 不用php做网站正规网站优化公司
  • 怎样才能在百度上搜到自己的网站六六seo基础运营第三讲
  • 付费网站推广谷歌独立站seo
  • 做电影网站被抓广告设计与制作需要学什么
  • 有没有教做蛋糕的网站seo排名是什么
  • 可以免费做网站推广的平台东莞疫情最新数据
  • 杭州科技公司网站建设百度指数大数据
  • 设计师经常看的appseo网站推广工作内容
  • 网站开发的收入关键词优化外包服务
  • 建立网站的英语鸿星尔克网络营销案例分析
  • 网站后台无ftp微信公众号怎么推广
  • 广告拍摄制作公司厦门seo排名扣费
  • 广州市建设和水务局网站百度快照搜索引擎
  • 天津市建设信息工程网sem优化服务公司
  • 长沙私人做网站微商引流推广
  • 福州网站建设加q479185700福建seo快速排名优化
  • 绍兴网站建设模板网站站长工具传媒
  • 北京网站制作与营销培训b2b平台
  • 开发公司资质审查用假资料后果深圳网站建设专业乐云seo
  • 中国建设银行官网站下载中心快速网站搭建
  • 元宇宙游戏开发莆田网站建设优化
  • 做快手电商需要什么条件百度seo排名优化是什么
  • 自己做购物网站怎么做清远新闻最新消息
  • 青岛市黄岛区网站建设市场营销策略有哪4种