B. 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 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 123 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 <iostream>
#include <bits/stdc++.h>

using namespace std;

int a[100005];
int main()
{
    int n,x,pos,q;
    long long mi;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    cin>>q;
    sort(a,a+n);
    while(q--)
    {
        scanf("%d",&x);
        if(a[0]>x)
            cout<<'0'<<endl;
        else if(a[n-1]<x)
            cout<<n<<endl;
        else
        {
            int head=0,tail=n-1,mid;
            while(head<=tail)
            {
                mid=(head+tail)/2;
                if(a[mid]<=x)
                {
                    pos=mid;
                    head=mid+1;
                }
                else
                {
                    tail=mid-1;
                }
            }
            cout<<pos+1<<endl;
        }
    }
    return 0;
}

<think>Hmm, the user is asking about the meaning of "brandy" in the context of Allwinner software after seeing multiple references about Allwinner A33/R16 development. Interesting pivot from alcoholic beverages to embedded systems! First let's analyze the context clues: The citations all point to "brandy" being a directory in Allwinner's SDK structure (lichee/brandy), specifically containing u-boot related code and build scripts. The user previously asked about Brandy the drink, but now clearly wants the tech definition. Key observations from references: - Reference [1][2] show build.sh scripts handling u-boot binaries in brandy folder - Reference [3] lists brandy under lichee as "boot related source code" - Reference [4]'s config flow places it in boot context - Reference [5] links it to Android compilation Ah-ha! The pattern emerges: In Allwinner terminology, "brandy" is their proprietary bootloader framework. It's not random - the name plays on "boot" concepts (like the drink's "distilled essence" meaning) while distinguishing from generic u-boot. User's probably working with Allwinner chips (A33/R16) and stumbled upon this directory. Their real need is understanding the SDK structure for development. Should emphasize: - Location in lichee directory - Contains customized u-boot - Managed by build.sh scripts - Platform-specific (sun8iwXX naming) The packaging process in references [1][2] is particularly telling - brandy handles embedding u-boot into final images. That's the core differentiator from standard u-boot. ...Also noting the Tina Linux references suggest this is for embedded Linux/Android systems. User might be porting OS or debugging boot issues. Should prepare follow-ups about build configuration in case they ask next. </think>在全志(Allwinner)软件生态中,**Brandy** 是一个专有的**引导加载程序(Bootloader)开发框架**,主要用于定制和编译 U-Boot(通用引导加载程序)。以下是其核心定义与技术解析: --- ### 一、Brandy 的定义与作用 1. **功能定位** Brandy 是全志 SDK 中负责 **Bootloader 开发与集成的核心模块**,通过对标准 U-Boot 进行深度定制,适配全志芯片的硬件特性(如启动流程、时钟初始化、DDR 控制器配置等)。 2. **目录结构** 在 Allwinner SDK 中(如 Tina Linux),Brandy 通常位于 `lichee/` 目录下,例如: ```bash lichee/ └── brandy/ # Bootloader 开发框架 ├── u-boot-2011.09/ # 定制版 U-Boot 源码 └── build.sh # 编译脚本 ``` 引用显示其输出文件路径为 `/lichee/brandy/u-boot-2011.09/../../tools/pack/chips/sun8iw5p1/bin/u-boot-sun8iw5p1.bin`[^2]。 3. **关键操作** - **编译流程**:通过执行 `build.sh` 脚本选择芯片平台(如 `PLATFORM="sun8iw3p1"`[^1]),生成适配特定 SoC 的 U-Boot 二进制文件。 - **打包集成**:将生成的 U-Boot 二进制文件嵌入最终固件镜像(如 `.img` 文件),实现系统启动时的硬件初始化[^1][^5]。 --- ### 二、Brandy 的工作流程(以全志 A33 为例) ```mermaid graph LR A[编辑 build.sh 脚本] --> B{设置芯片平台<br>PLATFORM="sun8iw3p1"} B --> C[执行 ./build.sh] C --> D[编译定制化 U-Boot] D --> E[输出 u-boot-sun8iw3p1.bin] E --> F[集成到系统镜像.img] ``` 1. **配置平台参数**:在 `build.sh` 中指定 SoC 型号(如 `sun8iw3p1` 对应 A33)。 2. **编译生成二进制**:脚本调用交叉编译工具链生成 U-Boot 文件。 3. **镜像打包**:通过 `pack` 工具将二进制文件写入固件镜像的引导分区[^1][^2][^5]。 --- ### 三、技术特点 1. **硬件适配层** 提供全志芯片专用的驱动和初始化代码,例如: - DDR 内存控制器配置 - 安全启动(Secure Boot)支持 - 多阶段启动流程(SPL → U-Boot) 2. **构建系统集成** 与 Tina Linux 的编译框架深度整合,可通过顶层 `build.sh` 统一调用: ```bash ./build.sh config # 选择平台(如 linux/tina) ./build.sh pack # 打包镜像 ``` 引用显示配置选项包含 `android`、`linux`、`tina` 等环境[^4]。 3. **版本依赖性** 不同 SoC 需匹配特定 Brandy 版本(如 A33 使用 `u-boot-2011.09`,R328 可能用更高版本)。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值