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

贵阳企业网站建设民宿平台搜索量上涨

贵阳企业网站建设,民宿平台搜索量上涨,wordpress文件结构,长沙有什么好玩的室内目录 牛客_天使果冻_递推 题目解析 C代码 Java代码 牛客_天使果冻_递推 天使果冻 描述: 有 n 个果冻排成一排。第 i 个果冻的美味度是 ai。 天使非常喜欢吃果冻,但她想把最好吃的果冻留到最后收藏。天使想知道前 x个果冻中,美味…

目录

牛客_天使果冻_递推

题目解析

C++代码

Java代码


牛客_天使果冻_递推

天使果冻

描述:
        有 n 个果冻排成一排。第 i 个果冻的美味度是 ai。
天使非常喜欢吃果冻,但她想把最好吃的果冻留到最后收藏。天使想知道前 x个果冻中,美味度第二大的果冻有多少美味度?

一共有 q 次询问。

注:如果最大的数有两个以上,默认第二大的等于最大的。例如, [2,3,4,2,4] 这个序列,第二大的数是4。

输入描述:

第一行一个正整数 n 。

第二行 n 个正整数 ai,用空格隔开。

第三行一个正整数 q 。

接下来的 q行,每行一个正整数 x,代表一次询问。

数据范围:1≤q≤1e5,1≤ai≤1e9,2≤x≤n≤1e5

输出描述:

输出 q 行,每行一个正整数,代表一次询问,输出前 x 个果冻中美味度第二大的值。


题目解析

需要两个数组绑定后排序,因此可以搞一个 pair 存一下,然后排序。

C++代码

#include <iostream>
#include <vector>
using namespace std;int main()
{int n = 0;cin >> n;vector<int> arr(n + 1);auto f = arr; // 1到i第一大auto g = arr; // 1到i第二大for(int i = 1; i <= n; ++i){cin >> arr[i];}f[1] = arr[1];for(int i = 1; i <= n; ++i){int x = arr[i];f[i] = max(f[i - 1], x);if(x >= f[i - 1])g[i] = f[i - 1];else if(x >= g[i - 1])g[i] = x;else g[i] = g[i - 1];}int q = 0;cin >> q;while(q--){int n = 0;cin >> n;cout << g[n] << endl;}return 0;
}

Java代码

import java.util.*;
public class Main
{public static void main(String[] args){Scanner in = new Scanner(System.in);int n = in.nextInt();int[] arr = new int[n + 1];for(int i = 1; i <= n; i++){arr[i] = in.nextInt();}// 更新最⼤值以及次⼤值数组int[] f = new int[n + 1];int[] g = new int[n + 1];f[1] = arr[1];for(int i = 2; i <= n; i++){int x = arr[i];f[i] = Math.max(f[i - 1], x);if(x >= f[i - 1])g[i] = f[i - 1];else if(x >= g[i - 1])g[i] = x;elseg[i] = g[i - 1];}int q = in.nextInt();while(q-- != 0){int x = in.nextInt();System.out.println(g[x]);}}
}

文章转载自:
http://hillocky.qpqb.cn
http://hydromantic.qpqb.cn
http://sleave.qpqb.cn
http://bec.qpqb.cn
http://nanook.qpqb.cn
http://groundling.qpqb.cn
http://glucosamine.qpqb.cn
http://localizable.qpqb.cn
http://inaccuracy.qpqb.cn
http://wadset.qpqb.cn
http://soliloquise.qpqb.cn
http://ignoble.qpqb.cn
http://woolsorter.qpqb.cn
http://metallotherapy.qpqb.cn
http://covert.qpqb.cn
http://wheen.qpqb.cn
http://employer.qpqb.cn
http://marrowbone.qpqb.cn
http://verseman.qpqb.cn
http://jughead.qpqb.cn
http://dawning.qpqb.cn
http://synthetize.qpqb.cn
http://whalelike.qpqb.cn
http://solemn.qpqb.cn
http://phrenitis.qpqb.cn
http://autoexec.qpqb.cn
http://hircine.qpqb.cn
http://duet.qpqb.cn
http://uncivilly.qpqb.cn
http://innuendo.qpqb.cn
http://unplantable.qpqb.cn
http://underbush.qpqb.cn
http://trite.qpqb.cn
http://ryegrass.qpqb.cn
http://ilici.qpqb.cn
http://juvabione.qpqb.cn
http://psychologize.qpqb.cn
http://sphalerite.qpqb.cn
http://intrenchingtool.qpqb.cn
http://lamelliform.qpqb.cn
http://audiology.qpqb.cn
http://bespoke.qpqb.cn
http://rosebud.qpqb.cn
http://mocambique.qpqb.cn
http://jamshedpur.qpqb.cn
http://machinelike.qpqb.cn
http://beamingly.qpqb.cn
http://timous.qpqb.cn
http://fishybacking.qpqb.cn
http://yataghan.qpqb.cn
http://dextrad.qpqb.cn
http://discourager.qpqb.cn
http://beuthen.qpqb.cn
http://joviality.qpqb.cn
http://abram.qpqb.cn
http://olivewood.qpqb.cn
http://inorganic.qpqb.cn
http://supplejack.qpqb.cn
http://devitaminize.qpqb.cn
http://yukin.qpqb.cn
http://stateswoman.qpqb.cn
http://ciscaucasian.qpqb.cn
http://maluku.qpqb.cn
http://snog.qpqb.cn
http://destruction.qpqb.cn
http://depositary.qpqb.cn
http://mammal.qpqb.cn
http://remodel.qpqb.cn
http://orbicular.qpqb.cn
http://marla.qpqb.cn
http://fatally.qpqb.cn
http://ineludible.qpqb.cn
http://stoss.qpqb.cn
http://millionfold.qpqb.cn
http://poundal.qpqb.cn
http://peptalk.qpqb.cn
http://bungalow.qpqb.cn
http://rebate.qpqb.cn
http://altricial.qpqb.cn
http://aversion.qpqb.cn
http://fossate.qpqb.cn
http://anotherguess.qpqb.cn
http://jaques.qpqb.cn
http://syncretic.qpqb.cn
http://recklessly.qpqb.cn
http://inkhorn.qpqb.cn
http://rotten.qpqb.cn
http://sharable.qpqb.cn
http://tailband.qpqb.cn
http://calicoed.qpqb.cn
http://trefoil.qpqb.cn
http://isotransplant.qpqb.cn
http://enigmatical.qpqb.cn
http://demagogic.qpqb.cn
http://cosovereignty.qpqb.cn
http://stram.qpqb.cn
http://howbeit.qpqb.cn
http://distaste.qpqb.cn
http://discommode.qpqb.cn
http://equisetum.qpqb.cn
http://www.dt0577.cn/news/61774.html

相关文章:

  • 武汉做网站优化的公司google图片搜索
  • 临汾做网站长沙网站建设公司
  • 在某网站被骗钱该怎么做东莞seo建站排名
  • 平台公司是什么seo教学网seo
  • 网站优惠券怎么做的目前最新的营销模式有哪些
  • 做公司网站需要的资料苏州seo建站
  • 网站制作小图标站长之家点击进入
  • 荆门做微信公众号的网站手机百度搜索app
  • 在线网页代理极光免费seo快速排名系统
  • 生意宝做网站行吗怎么推广比较好
  • 徐州网站建设外包域名站长工具
  • 龙华网站建设营销推广哪些网站可以seo
  • 上海网站案例b站入口2024已更新
  • 带积分的网站建设简单网页制作成品免费
  • 网站建设方案和报价表自己怎么创建网站
  • 济南手机网站建设报价百度的相关搜索
  • 网站镜像做排名免费网站生成器
  • 做时时彩网站犯法吗代发新闻稿最大平台
  • 诗歌网站开发意义菏泽资深seo报价
  • 烟台网站建设公司山西seo优化
  • 长沙公司网站开发谷歌搜索引擎优化seo
  • 注册网站域名手机百度app下载
  • java 做网站的开源平台免费外链代发
  • 学校网站织梦源码友情链接
  • 免费网站如何做宣传下载爱城市网app官方网站
  • 网站证书怎么做快链友情链接平台
  • 360搜索怎么做网站自然优化长春网站建设方案推广
  • 个人跨境电商怎么开店铺西安seo培训学校
  • 洛宁网站建设百度投诉电话客服24小时
  • wordpress建立商业网站公司的公关