POJ 1682 Clans on the Three Gorges

本文介绍了一个关于在三个峡谷间合理搭建桥梁以连接不同部落的算法问题。通过动态规划的方法,解决了三维空间中桥梁搭建的成本最小化问题。

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

Description
On the banks of the Three Gorges of the Yangtze River live some old clans. For historical reasons, clans on the same gorge hate each other, and conflicts often arise between them for lands and recourses. On the contrary they have a long and deep friendship with the clans on the other gorges. But it’s difficult for them to travel to the other sides of the gorge because of the torrent flow of the Yangtze River.
One day they decide to build suspension bridges between the gorges. The gorges have three banks (figure 1), and each bank is rolling so clans have different altitude. Every clan will not share a same bridge with other clans on the same bank, so there must be at least one bridge for each clan. And for safety reason, bridges are not allowed to cross each other overhead, or if a bridge collapsed, it would fall on another one. Experts point out that if the altitudes of the two ends of a bridge are different, the bridge will be troublesome to build and cost more. It’s estimated that the cost of a bridge is equal to the fall of the ends of the bridge. The clans are not rich, so they employ you to find a solution to minimize the cost to build the suspension bridges to satisfy their demand.
As show in figure 1, the three gorges are named X, Y and Z respectively. A clan is represented by a cycle, with its name and altitude in. Clans on gorge X are named x1, x2… xn in counter-clockwise order. Those on gorge Y and gorge Z are y1, y2… ym and z1, z2? zk in counter-clockwise order too. A bridge is represented by a line between two clans with its cost on it. No two lines can intersect and no clan has zero degree according to the description of this problem.
For example, figure 2 is invalid solution because the two bridges intersect. Figure 3 is also invalid for the reason that clan y1 doesn’t has a bridge for its own. Figure 1 and Figure 4 both are valid solutions for there are no intersected bridges or isolated clan in these solutions. The cost of a solution is the sum of all the costs of the bridges in the solution. And the cost of a bridge is equal to the absolute value of the difference of the heights of the two ends. So figure 1 has cost 11 against 14 of figure 4. It’s clear that figure 1 is a better solution. In fact, it’s one of the best solutions. You are required to write a program to find the minimum cost.


【题目分析】
蒟蒻看到之后不会做,只会解决二维的问题。然后就借鉴了别人的题解(说的好听,就是ctrl+c ctrl+v)。这道题的思路大概就是这样:
1、两两解决,共三组。dp[i][j]表示一面匹配到i,另一面匹配到j的情况。
2、将这三组合起来。
合并的时候由于不能交叉所以只有几种情况,然后写出来(找到最小值),就可以了。


【代码】

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
int n,m,p,a[150],b[150],c[150],xz[150][150],xy[150][150],yz[150][150],ans,tt;
void read()
{
    scanf("%d%d%d",&m,&n,&p);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=m;i++) scanf("%d",&b[i]);
    for(int i=1;i<=p;i++) scanf("%d",&c[i]);
    for(int i=0;i<150;i++)
        for(int j=0;j<150;j++)
            xz[i][j]=xy[i][j]=yz[i][j]=999999;
    ans=999999;
}

void go()
{
    xz[0][p+1]=0;
    for(int i=1;i<=n;i++)
        for(int j=p;j>=1;j--)
            xz[i][j]=min(min(xz[i-1][j+1],xz[i-1][j]),xz[i][j+1])+abs(a[i]-c[j]);
    xy[n+1][0]=0;
    for(int i=n;i>=1;i--)
        for(int j=1;j<=m;j++)
            xy[i][j]=min(min(xy[i+1][j-1],xy[i+1][j]),xy[i][j-1])+abs(a[i]-b[j]);
    yz[m+1][0]=0;
    for(int i=m;i>=1;i--)
        for(int j=1;j<=p;j++)
            yz[i][j]=min(min(yz[i+1][j-1],yz[i+1][j]),yz[i][j-1])+abs(b[i]-c[j]);
    for(int i=0;i<=n+1;i++)
        for(int j=0;j<=m+1;j++)
            for(int k=0;k<=p+1;k++)
            {
                ans=min(ans,xy[i][j]+xz[i][k]+yz[j][k]);
                ans=min(ans,xy[i][j]+xz[i][k]+yz[j+1][k]);  
                ans=min(ans,xy[i+1][j]+xz[i][k]+yz[j][k]);  
                ans=min(ans,xy[i][j]+xz[i][k+1]+yz[j][k]);
                ans=min(ans,xy[i+1][j]+xz[i][k]+yz[j+1][k]);  
                ans=min(ans,xy[i][j]+xz[i][k+1]+yz[j+1][k]);  
                ans=min(ans,xy[i+1][j]+xz[i][k+1]+yz[j][k]);
                ans=min(ans,xy[i+1][j]+xz[i][k+1]+yz[j+1][k]);
            }
    printf("%d\n",ans);
}

int main()
{
    scanf("%d",&tt);
    while(tt--)
    {
        read();
        go();
    }
    return 0;
}
智能网联汽车的安全员高级考试涉及多个方面的专业知识,包括但不限于自动驾驶技术原理、车辆传感器融合、网络安全防护以及法律法规等内容。以下是针对该主题的些核心知识点解析: ### 关于智能网联车安全员高级考试的核心内容 #### 1. 自动驾驶分级标准 国际自动机工程师学会(SAE International)定义了六个级别的自动驾驶等级,从L0到L5[^1]。其中,L3及以上级别需要安全员具备更高的应急处理能力。 #### 2. 车辆感知系统的组成与功能 智能网联车通常配备多种传感器,如激光雷达、毫米波雷达、摄像头和超声波传感器等。这些设备协同工作以实现环境感知、障碍物检测等功能[^2]。 #### 3. 数据通信与网络安全 智能网联车依赖V2X(Vehicle-to-Everything)技术进行数据交换,在此过程中需防范潜在的网络攻击风险,例如中间人攻击或恶意软件入侵[^3]。 #### 4. 法律法规要求 不同国家和地区对于无人驾驶测试及运营有着严格的规定,考生应熟悉当地交通法典中有关自动化驾驶部分的具体条款[^4]。 ```python # 示例代码:模拟简单决策逻辑 def decide_action(sensor_data): if sensor_data['obstacle'] and not sensor_data['emergency']: return 'slow_down' elif sensor_data['pedestrian_crossing']: return 'stop_and_yield' else: return 'continue_driving' example_input = {'obstacle': True, 'emergency': False, 'pedestrian_crossing': False} action = decide_action(example_input) print(f"Action to take: {action}") ``` 需要注意的是,“橙点同学”作为特定平台上的学习资源名称,并不提供官方认证的标准答案集;建议通过正规渠道获取教材并参加培训课程来准备此类资格认证考试。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值