Maximum GCD UVA - 11827 (gcd ,输入)

本文介绍了一道算法题目,要求找出一组整数中任意两数的最大公约数(GCD)。通过输入多个测试用例,每组用例包含若干正整数,需计算并输出这些整数间的最大GCD。文章提供了完整的C++实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Given the N integers, you have to find the maximum GCD (greatest common divisor) of every possible
pair of these integers.
Input
The first line of input is an integer N (1 < N < 100) that determines the number of test cases.
The following N lines are the N test cases. Each test case contains M (1 < M < 100) positive
integers that you have to find the maximum of GCD.
Output
For each test case show the maximum GCD of every possible pair.
Sample Input
3
10 20 30 40
7 5 12
125 15 25
Sample Output
20
1
25

暴力的gcd ,输入很少见,一直卡在这。。。

// 这个题真是醉了,居然卡在输入上

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

#define ll long long

using namespace std;

int gcd(int a,int b)
{
    if( a < b)
    {
        int tmp = a;
        a = b;
        b = tmp;
    }
    return b==0? a : gcd(b,a%b);    
}
int a[150];
int num[150];

int main()
{
    int n;
    scanf("%d",&n);
    getchar();     // 吸收回车 
    for(int i=0;i<n;i++)
    {
        int flag = 1;
        int cnt = 0;
        char ch;

        while( ( ch = getchar() ) != '\n')
        {
            if( '0' <= ch && ch <= '9')
                {
                    ungetc(ch,stdin);     // 如果是数字,将它退流 
                    scanf("%d",&a[cnt++]);
                }
        }

        int maxn;
        maxn = -1;
        int tmp;

        for(int j = 0; j < cnt; j ++)
            for(int k = 0; k < j; k ++)
                {
                    tmp = gcd( a[j], a[k] );
                    if( tmp > maxn)
                        maxn = tmp;
                }

        printf("%d\n",maxn);
    }

    return 0;
}
<think>我们正在讨论YARN调度器中的`yarn.scheduler.maximum-allocation-vcores`参数。根据用户提供的引用,特别是引用[2]和引用[5],我们可以总结如下:1.**参数含义**:`yarn.scheduler.maximum-allocation-vcores`定义了集群中单个容器(Container)可以请求的最大虚拟核心数(vcores)。任何容器请求的vcores超过这个值都会被限制到该最大值。2.**默认值**:根据引用[5],默认值为4。3.**配置位置**:在`yarn-site.xml`文件中配置。4.**业务设置**:引用[2]提到,根据业务需求设置,并且指出经过Cloudera测试,vcores小于5时性能最佳(因此他们设置最大为4c)。5.**与最小值的关联**:该参数通常与`yarn.scheduler.minimum-allocation-vcores`(容器请求的最小vcores)一起使用,共同定义了容器vcores请求的允许范围。6.**注意事项**:-该参数是集群级别的,对所有队列生效(除非队列有覆盖配置,但通常不是这样)。-在CapacityScheduler中,队列可以有自己的最大资源限制,但容器级别的最大分配仍然受此全局参数限制。-设置太大可能导致大任务垄断资源,设置太小可能限制应用性能。7.**配置示例**(参考引用[2]):```xml<property><name>yarn.scheduler.maximum-allocation-vcores</name><value>4</value></property>```8.**调优建议**:-考虑集群节点资源:例如,如果每个NodeManager配置了32个vcores(如引用[2]所示),则设置最大值不超过节点的vcores数(通常不会超过,因为一个容器只能在一个节点上运行)。-结合应用需求:如果应用中有需要多核的任务(如并行计算),则适当增大;反之,若应用均为轻量任务,则保持较小值以避免大任务占用过多资源。9.**其他相关参数**:-`yarn.nodemanager.resource.cpu-vcores`:每个NodeManager可分配的vcores总数(如32c)。-`yarn.scheduler.minimum-allocation-vcores`:容器请求的最小vcores(如2c)。10.**性能考虑**:引用[2]提到vcores在小于5时性能最佳,所以通常设置最大值为4或5。现在,根据用户要求,回答关于`yarn.scheduler.maximum-allocation-vcores`的配置说明及用法。</think> ### `yarn.scheduler.maximum-allocation-vcores` 配置详解 #### 1. **参数定义与作用** `yarn.scheduler.maximum-allocation-vcores` 是 YARN 资源调度器中的核心参数,用于定义 **单个容器(Container)可申请的最大虚拟核数(vcores)**。作用包括: - **资源隔离限制**:防止单个任务独占集群资源(如配置最大为 4c,则任何容器请求超过 4 vcores 会被强制截断)[^2][^5] - **调度公平性**:与最小值配合实现资源分配的弹性区间,例如: $$ \text{min-vcores} \leq \text{request-vcores} \leq \text{max-vcores} $$ - **防止资源碎片**:避免超大容器导致小任务无法调度 #### 2. **配置规则与关联参数** | **参数** | **默认值** | **依赖关系** | **典型生产环境值** | |---------|-----------|------------|------------------| | `yarn.scheduler.maximum-allocation-vcores` | 4 vcores | 需满足:<br> $$ \text{min-vcores} \leq \text{max-vcores} \leq \text{NodeManager-vcores} $$ | 4-8 vcores(依节点规模)[^2][^5] | | `yarn.scheduler.minimum-allocation-vcores` | 1 vcore | 必须 ≤ max-vcores | 2 vcores[^2] | | `yarn.nodemanager.resource.cpu-vcores` | 8 vcores | max-vcores ≤ 此值 | 32 vcores[^2] | > 💡 **关键约束**:最大分配值受节点物理资源限制,若配置值超过 `yarn.nodemanager.resource.cpu-vcores`,实际生效值为节点最大值。 #### 3. **配置文件示例 (`yarn-site.xml`)** ```xml <configuration> <!-- 单容器最大vcore配置 --> <property> <name>yarn.scheduler.maximum-allocation-vcores</name> <value>4</value> <!-- 通常设置为节点总vcores的1/8~1/4 --> </property> <!-- 关联配置 --> <property> <name>yarn.scheduler.minimum-allocation-vcores</name> <value>2</value> </property> <property> <name>yarn.nodemanager.resource.cpu-vcores</name> <value>32</value> <!-- 节点总vcores --> </property> </configuration> ``` #### 4. **性能优化建议** 1. **CPU密集型场景**: 若运行Spark ML或MPI作业,可适当增大(如 8 vcores),但需遵守: $$ \text{max-vcores} \leq \frac{\text{NodeManager-vcores}}{2} $$ (防止单节点过度竞争) 2. **低延迟场景**: 保持默认 4 vcores 或更低(Cloudera测试表明 vcores < 5 时性能最优[^2]) 3. **与内存协同**: 按比例配置vcores与内存,例如: ```python # 计算vcore与内存的推荐比例 vcore_mem_ratio = yarn.scheduler.maximum-allocation-mb / yarn.scheduler.maximum-allocation-vcores # 通常设置为 2GB/vcore ~ 4GB/vcore ``` #### 5. **队列级覆盖配置(Capacity Scheduler)** 在 `capacity-scheduler.xml` 中可为特定队列单独设置最大值: ```xml <!-- 为research队列设置独立上限 --> <property> <name>yarn.scheduler.capacity.root.research.maximum-allocation-vcores</name> <value>8</value> <!-- 需≤全局max-vcores --> </property> ``` > ⚠️ **注意**:子队列配置不能超过父队列限制[^3][^4] #### 6. **验证配置** 1. 重启 YARN 服务生效 2. 使用命令查看生效值: ```bash yarn rmadmin -getAllServiceConf | grep maximum-allocation-vcores ``` 3. 提交测试任务验证: ```bash yarn jar hadoop-mapreduce-client-testclient.jar \ TestAMRMTokens -container_vcores 5 # 请求5vcores应被拒绝 ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值