codeforces706B Interesting drink 排序+二分查找

基于Matlab-Simulink的大林算法控制系统设计与振铃消除实验 本文详细介绍了基于Matlab-Simulink的大林算法控制系统设计与振铃消除实验。通过分析纯滞后系统的控制难题,探讨大林算法在工业控制中的应用优势,并提供Matlab-Simulink环境搭建、控制器D(z)设计、振铃消除及仿真实验的完整流程。文章还对比了大林算法与PID控制的性能差异,为工程实践提供参考。 阅读详情

B. Interesting drink
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in n different shops in the city. It's known that the price of one bottle in the shop i is equal to xi coins.

Vasiliy plans to buy his favorite drink for q consecutive days. He knows, that on the i-th day he will be able to spent mi coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola".

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of shops in the city that sell Vasiliy's favourite drink.

The second line contains n integers xi (1 ≤ xi ≤ 100 000) — prices of the bottles of the drink in the i-th shop.

The third line contains a single integer q (1 ≤ q ≤ 100 000) — the number of days Vasiliy plans to buy the drink.

Then follow q lines each containing one integer mi (1 ≤ mi ≤ 109) — the number of coins Vasiliy can spent on the i-th day.

Output

Print q integers. The i-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the i-th day.

Example
input
5
3 10 8 6 11
4
1
10
3
11
output
0
4
1
5
Note

On the first day, Vasiliy won't be able to buy a drink in any of the shops.

On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.

On the third day, Vasiliy can buy a drink only in the shop number 1.

Finally, on the last day Vasiliy can buy a drink in any shop.



从大到小排个序,二分查找比输入的数大的第一个数,然后这个数的位置下标减一即输出


#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;

const int maxn = 100000;
int a[maxn + 5];

int main()
{
	int n, q, tmp;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	sort(a + 1, a + n + 1);
	cin >> q;
	while (q--) {
		scanf("%d", &tmp);
		int l, r;
		l = 1; r = n;
		while (l <= r) {
			int mid = (l + r) / 2;
			if (a[mid] > tmp) {
				r = mid - 1;
			}
			else {
				l = mid + 1;
			}
		}
		printf("%d\n", l - 1);
	}
	return 0;
}







【电路设计】带阻滤波器实战:从理论到Twin-T陷波电路实现 本文详细介绍了带阻滤波器的原理与Twin-T陷波电路的实战应用,从基础概念到工程实现全面解析。通过具体案例展示如何设计高Q值滤波器,解决电源噪声等实际问题,并分享PCB布局和元件选型的实用技巧,助力工程师提升电路设计能力。 阅读详情

相关推荐

用简单仿真链路产生 WiFi CSI(不依赖专用工具箱,matlab实现)

这篇文章详细介绍了使用MATLAB仿真生成WiFi信道状态信息(CSI)的过程。内容包括:准备工作(定义OFDM和MIMO参数)、基本参数设置(天线数、FFT点数等)、构造训练OFDM符号、多径瑞利信道建模、逐天线时分发射接收处理、CSI信道估计方法,以及幅值和相位的可视化。通过BPSK调制和瑞利衰落信道仿真,实现了简单的CSI生成流程,为初学者理解CSI产生机理提供了直观指导。文章强调这仅是基础仿真,更深入的研究需要实际数据采集。文末还提供了WiFi指纹定位的相关参考资料。

静水流深,沧笙踏歌 1217

CodeForces 706B Interesting drink

B. Interesting drink time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasiliy likes to rest after a hard wor

Calm微笑 1402

(超详细)Scala环境搭建(scala-2.12.15、IDEA2021.1.3)

Scala环境搭建(scala-2.12.15、IDEA2021.1.3) JunLeon——go big or go home 目录 Scala环境搭建(scala-2.12.15、IDEA2021.1.3) 一、Scala概述 1、什么是Scala? 2、Scala发展史 3、Scala与Java的关系 二、Scala环境搭建 1、环境准备 2、Scala安装与配置环境变量 3、验证Scala 三、编写第一个Scala程序 1、使用IDEA创建maven工程 2、.

JunLeon的博客 3万+

B. Taxi、B. Interesting drink、B. Fence

本文介绍了三个算法题的解题思路与实现代码:1)《B.Taxi》使用双指针法对乘客分组,每辆车最多载4人;2)《B.Interestingdrink》通过排序和二分查找确定每日预算能购买的商品数量;3)《B.Fence》利用前缀和寻找高度和最小的k块连续木板。三题均采用高效算法(双指针、二分查找、前缀和)解决问题,代码实现简洁高效。

m0_73817832的博客 262

本地部署 Anything LLM+Ollama+DeepSeek R1 大模型并实现外部访问

DeepSeek 一经发布就引起社会的广泛的关注,因为 DeepSeek 的价格低廉,性能卓越,提供了多种使用方式,满足不同用户的需求和场景。本文将详细的介绍如何在本地 Windows 上安装部署 Anything LLM + Ollama 来实现用户和 DeepSeek-r1 对话的功能以及利用路由侠内网穿透实现外网访问。

lyxnwct的博客 1910

Android Keystore与StrongBox实战:密钥存储与使用全指南

在移动应用安全领域,加密密钥的存储与管理往往比加密算法本身更关键。如果密钥以硬编码或明文文件形式存在,即使使用AES、RSA等强加密算法,攻击者通过反编译即可轻易突破。Android系统从6.0开始提供Keystore系统,将密钥生成与运算隔离在安全环境中;TEE(可信执行环境)和StrongBox硬件安全模块则进一步把密钥锁进硬件边界,实现“密钥材料不可导出”的防护目标。理解KeyStore的原理与能力,不仅能让开发者在合规审查、上架审核中拿出有力依据,还能在不依赖第三方SDK的前提下,通过Code Le

weixin_29164185的博客 289

B. Interesting drink

B. Interesting drink Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink “Beecola”, which can be bought in n different shops in the city. It’s known that the price of one b

tatan_的博客 243

功能安全到底是什么?一文讲透ISO 26262与ASIL核心概念

在汽车电子与软件开发中,可靠性常被误认为就是安全,但两者关注点截然不同。功能安全的核心不是让系统永远不出错,而是当故障发生时,如何通过ASIL等级划分、安全目标设定与安全机制设计,将风险控制在可接受范围内。ISO 26262作为国际功能安全标准,为从危害分析到软硬件开发的整个过程提供了一套可追溯的工程方法论。随着自动驾驶、线控底盘等复杂系统的普及,功能安全与网络安全、预期功能安全(SOTIF)的协同愈发关键,也成为系统工程师、软件工程师必须理解的基础能力。无论是评估第三方软件组件鉴定报告,还是进行FMEDA

weixin_29192141的博客 265

Codeforces 706B Interesting drink 【二分】

Interesting drink time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasiliy likes to rest after a hard work, so yo...

weixin_34235105的博客 281

Camera Sensor接口协议全解析(六)聚焦onsemi HiSPi接口的技术突破与应用实践

摘要: Onsemi HiSPi是一种高速并行接口协议,专为高分辨率图像传感器设计,具备1600 Mbps传输速率、低功耗和高兼容性特点。通过对比DVP、MIPI CSI-2等主流协议,HiSPi在工业/医疗领域表现突出,支持动态功耗控制、多ROI和CRC校验。其创新架构包含多PHY设计,提供分组SP、流SP等多种工作模式,满足灵活传输需求。实际应用中,HiSPi在PCB缺陷检测(5μm精度)和液晶面板检测(0.3% Mura检出率)等场景展现卓越性能,成为高速成像领域的关键技术。

GateWorld的博客 1452

基于大模型的急性重症胰腺炎全流程预测与诊疗方案研究

本研究构建了基于大模型的急性重症胰腺炎(SAP)全流程预测与诊疗系统,实现了从术前风险评估到术后康复管理的精准诊疗闭环。通过整合临床信息、实验室检查和影像学等多源数据,模型在测试集上预测准确率达X%,AUC为X,显著优于传统评分系统。研究创新性地将预测结果应用于手术方案制定、麻醉决策、并发症防控及个性化护理,形成智能化诊疗方案。验证结果显示模型具有良好的稳定性和临床适用性,同时配套的健康教育体系提升了患者自我管理能力。尽管存在样本局限性和模型可解释性等不足,该研究为SAP的精准诊疗提供了新范式,未来可通过扩

嵌入式毕设/课设资料清单(速查手册·文档模板·题库,持续更新)→ 见最新文章 1131

Interesting drink (三种做法)CodeForces - 706B

My birthday is coming up and traditionally I’m serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are coming to my party and each of ...

qq_40604099的博客 774

数据挖掘实战-基于LSTM时间序列模型的香烟销售预测分析

本文介绍了基于LSTM时间序列模型的香烟销售预测分析实验。实验背景为烟草市场竞争激烈,企业需提高销售预测准确性以优化生产、库存和营销策略。LSTM模型因其处理长序列数据的能力被选为预测工具。实验步骤包括数据准备、特征工程、模型构建、训练与评估及结果分析。数据集来自某市门店的销售数据,技术工具为Python 3.9和Jupyter Notebook。实验过程涵盖数据导入、预处理、产品销售与区域销售分析、销售预测(包括销售额、销量、利润及海通店销售额预测)。

m0_64336780的博客 8971

【二分】Codeforces 706B Interesting drink

题目链接:   http://codeforces.com/problemset/problem/706/B 题目大意:   n(1 ≤ n ≤ 100 000)个商店卖一个东西,每个商店的价格Ai,你有m(1≤m≤100 000)天,每天有Cj的钱,问每天可以负的起的商店数。 题目思路:   【二分】   排个序,二分。 1 // 2 //by co...

PHILIP0917的博客 201

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

codeforces 706B Interesting drink

点击打开链接 B. Interesting drink time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasiliy likes to rest afte

zhang__liuchen的博客 440

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

codeforces706B(二分)之Interesting drink

B. Interesting drink time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasiliy likes to rest after a hard wor

ESESZB的博客 726

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

CodeForces 706B Interesting drink【水题】

Description Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in n different s

Joeferyの博客 776

Codeforces - 706B - Interesting drink - 二分 - 简单dp

https://codeforces.com/problemset/problem/706/B 因为没有看见 $x_i$ 的上限是 $10^5$ ,就用了二分去做,实际上这道题因为可乐的价格上限是 $10^6$ ,可以用复杂度为 $O(max(x_i))$ 的dp去做。 也就是说,当这道题的可乐数量上升,二分就容易超时,而可乐的价格上升则dp容易爆内存且超时。各有所长 #include&...

weixin_30568591的博客 162

【Codeforces】-706B-Interesting drink(二分)

B. Interesting drink time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasiliy likes to rest after a hard wor

Bear1998的博客 635

CodeForces - 706B Interesting drink(二分查找)

Interesting drink Problem Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bou...

173

Codeforces 706B Interesting drink

B. Interesting drink time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Vasiliy likes to rest after a hard w...

weixin_33963594的博客 168

Codeforces 706B:Interesting drink(二分+排序)

B. Interesting drink time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasiliy likes to rest after a hard wor

zugofn的博客 547

codeforces | java | 706B | Interesting drink

【代码】codeforces | java | 706B | Interesting drink。

iCling的博客 254
上一篇: codeforces711B Chris and Magic Square 简单枚举
下一篇: codeforces706C Hard problem 动态规划
Daemoonn
博客等级 码龄11年 42粉丝 198原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址