Fence Repair(POJ-3253)

Problem Description

Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needsN (1 ≤ N ≤ 20,000) planks of wood, each having some integer lengthLi (1 ≤ Li ≤ 50,000) units. He then purchases a single long board just long enough to saw into theN planks (i.e., whose length is the sum of the lengths Li). FJ is ignoring the "kerf", the extra length lost to sawdust when a sawcut is made; you should ignore it, too.

FJ sadly realizes that he doesn't own a saw with which to cut the wood, so he mosies over to Farmer Don's Farm with this long board and politely asks if he may borrow a saw.

Farmer Don, a closet capitalist, doesn't lend FJ a saw but instead offers to charge Farmer John for each of theN-1 cuts in the plank. The charge to cut a piece of wood is exactly equal to its length. Cutting a plank of length 21 costs 21 cents.

Farmer Don then lets Farmer John decide the order and locations to cut the plank. Help Farmer John determine the minimum amount of money he can spend to create theN planks. FJ knows that he can cut the board in various different orders which will result in different charges since the resulting intermediate planks are of different lengths.

Input

Line 1: One integer N, the number of planks

Lines 2..N+1: Each line contains a single integer describing the length of a needed plank

Output

Line 1: One integer: the minimum amount of money he must spend to makeN-1 cuts

Sample Input

3
8
5
8

Sample Output

34

题意:要把一个木板截成给定长度的几块小木板,每一次费用是当前木板的长度,给出要截成的小木板的个数 n 与长度,求最小花费。

思路:根据贪心思想,要使费用最小,就要让每次锯成的两块木板的长度和最小。使用优先队列,每次选择最小的两块木头相加,相加后再次进入队列,再选择最小的两块木头相加,依次类推,直至队列为空取得最小值。

Source Program

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<vector>
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define N 10001
#define MOD 123
#define E 1e-6
using namespace std;
priority_queue < int,vector<int>,greater<int> > q;//最小值优先的优先队列
int main()
{
    int n;
    scanf("%d",&n);

    for(int i=0;i<n;i++)
    {
        int temp;
        scanf("%d",&temp);
        q.push(temp);
    }

    long long sum=0;
    while(n!=1)//共截取n-1次
    {
        int a,b;

        a=q.top();//取队首元素
        q.pop();//队首元素出队
        b=q.top();//取队首元素
        q.pop();//队首元素出队

        sum+=a+b;//记录花费
        q.push(a+b);//队列中最小值与次小值的和入队

        n--;
    }

    printf("%lld\n",sum);

    return 0;
}

 

<think>嗯,用户之前遇到了在创建VMware STONITH代理时的错误,提示找不到fence_vmware代理。我之前指导他们检查是否安装了相关软件包,并安装必要的代理。现在用户执行了rpm查询,结果显示安装了fence-agents-vmware-rest和fence-agents-vmware-soap这两个包,但执行which fence_vmware时却找不到该命令。这说明用户可能遇到了软件包安装正确但命令不存在的问题。 首先,我需要确认这两个RPM包是否真的包含fence_vmware命令。可能的情况是,在较新的版本中,VMware的隔离代理被分成了不同的类型,比如基于REST和SOAP的,而传统的fence_vmware可能已被弃用或拆分成不同的二进制文件。例如,用户安装的可能是新的代理,如fence_vmware_rest或fence_vmware_soap,而不是旧的fence_vmware。 接下来,用户需要知道现在应该使用哪个命令代替fence_vmware。我需要检查这两个软件包提供的实际可执行文件是什么。通常,RPM包中的文件可以通过rpm -ql命令查看。例如,检查fence-agents-vmware-rest和fence-agents-vmware-soap安装了什么二进制文件。 另外,用户可能使用的是较新版本的fence-agents,其中VMware的代理被拆分成了不同的协议实现,比如SOAP和REST,而原来的fence_vmware可能已经被移除。因此,用户需要根据他们的环境选择正确的代理类型,比如fence_vmware_soap或fence_vmware_rest,并在创建STONITH设备时使用对应的代理名称。 同时,用户可能需要确认他们的集群环境是否需要使用新的代理类型,并确保对应的代理已正确安装。此外,检查文档或发行说明,确认fence_vmware是否已被替代,以及如何迁移到新的代理。 最后,用户可能需要更新他们的pcs命令,使用新的代理名称,比如fence_vmware_soap,并调整相应的参数,如可能的API版本或认证方式,特别是如果他们的VMware环境已经升级到使用REST API而不是旧的SOAP接口。</think>根据您的查询结果,系统安装了 **VMware REST/SOAP 接口的隔离代理**,但未找到传统的 `fence_vmware` 命令。这是新旧版本代理差异导致的兼容性问题,以下是详细解析: --- ### **原因分析** 1. **代理名称变化** 在较新版本的 `fence-agents` 中,VMware 隔离代理拆分为两种协议实现: - `fence_vmware_rest`:基于 **VMware REST API**(适用于 vSphere 7.0+) - `fence_vmware_soap`:基于 **VMware SOAP API**(适用于 vSphere 6.x 及更早版本) 2. **旧版命令弃用** 传统 `fence_vmware` 命令已废弃,您需要通过 **明确指定协议类型** 选择对应的代理。 --- ### **解决方案** **根据您的 VMware 版本选择代理类型:** #### 𝗔. 𝗩𝗠𝘄𝗮𝗿𝗲 𝘃𝗦𝗽𝗵𝗲𝗿𝗲 𝟳.𝟬+ (使用 REST API) ```bash pcs stonith create vmware_fence fence_vmware_rest \ cmk_host_map="server1:vm1;server2:vm2" \ ipaddr="vcenter.example.com" \ # 替换为您的vCenter地址 ssl=1 \ login="vmware_username" \ passwd="vmware_password" \ action="off" \ port="vm_name_in_vmware" \ delay=15 \ op monitor interval=60s ``` #### 𝗕. 𝗩𝗠𝘄𝗮𝗿𝗲 𝘃𝗦𝗽𝗵𝗲𝗿𝗲 𝟲.𝘅 𝗼𝗿 𝗲𝗮𝗿𝗹𝗶𝗲𝗿 (使用 SOAP API) ```bash pcs stonith create vmware_fence fence_vmware_soap \ cmk_host_map="server1:vm1;server2:vm2" \ ipaddr="vcenter.example.com" \ ssl=1 \ login="vmware_username" \ passwd="vmware_password" \ action="off" \ port="vm_name_in_vmware" \ delay=15 \ op monitor interval=60s ``` --- ### **关键参数调整说明** 1. **𝗶𝗽𝗮𝗱𝗱𝗿** - 必须指向 **vCenter Server** 的地址(而非 ESXi 主机) - 示例:`ipaddr="vcenter.example.com"` 2. **𝗽𝗼𝗿𝘁** - 确保与 VMware 中虚拟机的 **完整名称** 一致(区分大小写) 3. **𝗰𝗺𝗸_𝗵𝗼𝘀𝘁_𝗺𝗮𝗽** - 格式为 `物理节点名:虚拟机名`,多个映射用分号分隔 - 示例:`server1:vm1;server2:vm2` 4. **𝗦𝗦𝗟 配置** - 添加 `ssl=1` 参数以启用加密通信 - 如需忽略证书验证,可添加 `ssl_insecure=1` --- ### **验证代理可用性** ```bash # 测试 REST 代理 fence_vmware_rest -o metadata # 测试 SOAP 代理 fence_vmware_soap -o metadata ``` 正常应输出 XML 格式的代理参数说明。 --- ### **补充建议** 1. **权限配置** 在 vCenter 中为账号分配最小权限: - `Host.Configuration.ChangeSettings` - `VirtualMachine.Interact.PowerOff` 2. **防火墙规则** 确保集群节点能访问 vCenter 的 **443 端口**(REST/SOAP 均使用 HTTPS)。 3. **代理兼容性** - 如果从旧版升级,需删除原有配置后重建: ```bash pcs stonith delete vmware_fence ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值