搜索-O

  • 原题

    Description
    Inhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Committee has volunteered and has promised to organize the most honest contest ever. It was decided to connect computers for the contestants using a “star” topology - i.e. connect them all to a single central hub. To organize a truly honest contest, the Head of the Judging Committee has decreed to place all contestants evenly around the hub on an equal distance from it.

    To buy network cables, the Judging Committee has contacted a local network solutions provider with a request to sell for them a specified number of cables with equal lengths. The Judging Committee wants the cables to be as long as possible to sit contestants as far from each other as possible.

    The Cable Master of the company was assigned to the task. He knows the length of each cable in the stock up to a centimeter, and he can cut them with a centimeter precision being told the length of the pieces he must cut. However, this time, the length is not known and the Cable Master is completely puzzled.

    You are to help the Cable Master, by writing a program that will determine the maximal possible length of a cable piece that can be cut from the cables in the stock, to get the specified number of pieces.

    Input
    The input consists of several testcases. The first line of each testcase contains two integer numbers N and K, separated by a space. N (1 ≤ N ≤ 10000) is the number of cables in the stock, and K (1 ≤ K ≤ 10000) is the number of requested pieces. The first line is followed by N lines with one number per line, that specify the length of each cable in the stock in meters. All cables are at least 1 centimeter and at most 100 kilometers in length. All lengths in the input are written with a centimeter precision, with exactly two digits after a decimal point.

    The input is ended by line containing two 0’s.

    Output
    For each testcase write to the output the maximal length (in meters) of the pieces that Cable Master may cut from the cables in the stock to get the requested number of pieces. The number must be written with a centimeter precision, with exactly two digits after a decimal point.

    If it is not possible to cut the requested number of pieces each one being at least one centimeter long, then the output must contain the single number “0.00” (without quotes).

    Sample Input
    4 11
    8.02
    7.43
    4.57
    5.39
    0 0

    Sample Output
    2.00

  • 思路解析
    题意:有n条绳子,分成11段相等的,问能使得最长为多长

  • AC代码

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define exp 1e-8
int n,k;
double a[10005],sum;
int judge(double s)
{
    int cnt = 0;
    for(int i = 0; i<n; i++)
    {
        cnt+=(int)(a[i]/s);
    }
    if(cnt>=k) return 1;
    return 0;
}
int main()
{
    int i;
    while(~scanf("%d%d",&n,&k),n+k)
    {
        sum = 0;
        for(i = 0; i<n; i++)
        {
            scanf("%lf",&a[i]);
            sum+=a[i];
        }
        sum = sum/k;
        double l = 0,r = sum;
        while(fabs(l-r)>exp)
        {
            double mid = (l+r)/2;
            if(judge(mid))
                l = mid;
            else
                r = mid;
        }
        printf("%.2f\n",l);
    }
    return 0;
}
03-22
<think>好的,用户现在问的是关于Linux中的“-o”选项。首先,我需要回顾之前的对话历史。用户之前询问了依赖文件,我给出了详细的解释,包括定义、分类、管理工具以及常见问题解决。现在用户提到了“-o”,这可能是一个命令行选项,常见于各种Linux命令中。 首先,要确定“-o”在不同命令中的不同含义。比如,在gcc中,-o用于指定输出文件名;在grep中,-o表示只输出匹配的部分;在find命令中,-o是逻辑或操作符。我需要分门别类地解释,确保用户理解每个上下文中的不同用法。 接下来,用户可能的意图是什么?他们可能在某个命令中遇到了“-o”选项,但不确定其具体作用,或者在使用时出现了问题,需要了解如何正确使用。考虑到用户之前询问的是依赖文件,可能他们正在编译程序,遇到了gcc的-o选项,或者在其他上下文中使用过。需要覆盖最常见的几种情况,并举例说明。 然后,需要确保回答结构清晰,逐步解释每个用法,避免混淆。可能用户是新手,所以需要用简单明了的语言,同时提供具体的命令示例,帮助他们理解。例如,在gcc中使用-o编译代码,生成可执行文件;在grep中提取特定模式的文本;在find中组合多个条件进行文件搜索。 另外,要注意用户可能遇到的常见问题,比如在shell脚本中使用逻辑运算符时,-o和-a的区别,或者在使用chmod时-o的不同含义。需要指出这些潜在的问题点,帮助用户避免错误。 最后,总结部分需要强调“-o”的多义性,提醒用户根据具体命令查阅手册,例如使用man命令或--help选项来获取详细信息。这样用户可以学会自主解决问题,提高他们的Linux使用技能。 检查是否有遗漏的常见命令中的-o选项,比如tar命令中的-o保留原文件属性,或者其他工具中的不同用法。确保覆盖全面,但不过于冗长。保持每个部分的简洁,用示例和场景说明,帮助用户更好地理解和记忆。</think>在 Linux 命令行中,`-o` 是一个常见的选项(option),但其具体含义会根据不同的命令而发生变化。以下是分场景解释: --- ### 一、通用规则 `-o` 通常表示 **output**(输出)或 **option**(选项),但需结合具体命令理解。以下分三类说明: --- ### 二、编译场景:`gcc` 或 `clang` 中的 `-o` - **作用**:指定输出文件的名称。 - **语法**: ```bash gcc input.c -o output_executable # 编译 input.c,生成名为 output_executable 的可执行文件 ``` - **对比默认行为**: 若不使用 `-o`,默认生成 `a.out`(C/C++)或 `a.exe`(Windows 交叉编译)。 **示例**: ```bash gcc hello.c -o myprogram # 输出文件名为 myprogram ``` --- ### 三、文本处理场景:`grep` 中的 `-o` - **作用**:仅输出匹配的文本片段(而非整行)。 - **语法**: ```bash grep -o "pattern" file.txt # 仅显示匹配的字符串 ``` **示例**: ```bash echo "error: file not found" | grep -o "error" # 输出:error ``` --- ### 四、逻辑操作场景:`find` 或 `test` 命令中的 `-o` - **作用**:表示逻辑 **或**(OR),用于组合多个条件。 - **语法**: ```bash find /path \( -name "*.txt" -o -name "*.log" \) # 查找 .txt 或 .log 文件 ``` **对比 `-a`**: - `-a` 表示逻辑 **与**(AND,可省略),`-o` 必须显式写出。 --- ### 五、其他常见命令中的 `-o` 1. **`sort` 命令** ```bash sort -o output.txt input.txt # 将排序结果保存到 output.txt(类似重定向 >) ``` 2. **`ssh` 命令** ```bash ssh -o Option=value user@host # 指定连接配置项(如超时时间) ``` 3. **`mount` 命令** ```bash mount -o options device dir # 指定挂载选项(如 ro 只读) ``` 4. **`shell 条件判断`** ```bash if [ "$a" -gt 0 -o "$b" -lt 10 ]; then ... # 测试 a>0 或 b<10(已过时,推荐用 `||`) ``` --- ### 六、注意事项 - **多义性**:`-o` 的含义完全取决于上下文。例如: ```bash chmod o+x file # 这里的 o 是 "others",与选项无关! ``` - **查阅手册**:遇到不确定的 `-o`,可通过 `man 命令名` 或 `命令 --help` 确认具体用途。 --- ### 总结 `-o` 是 Linux 命令中高频但多义的选项,核心功能通常与 **输出控制** 或 **逻辑操作** 相关。使用时需结合具体命令和场景,并通过手册验证其行为。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值