Truck History POJ - 1789 (prim)

Truck History

  POJ - 1789 

Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for vegetable delivery, other for furniture, or for bricks. The company has its own code describing each type of a truck. The code is simply a string of exactly seven lowercase letters (each letter on each position has a very special meaning but that is unimportant for this task). At the beginning of company's history, just a single truck type was used but later other types were derived from it, then from the new types another types were derived, and so on. 

Today, ACM is rich enough to pay historians to study its history. One thing historians tried to find out is so called derivation plan -- i.e. how the truck types were derived. They defined the distance of truck types as the number of positions with different letters in truck type codes. They also assumed that each truck type was derived from exactly one other truck type (except for the first truck type which was not derived from any other type). The quality of a derivation plan was then defined as 
1/Σ(to,td)d(to,td)

where the sum goes over all pairs of types in the derivation plan such that t  o is the original type and t  d the type derived from it and d(t  o,t  d) is the distance of the types. 
Since historians failed, you are to write a program to help them. Given the codes of truck types, your program should find the highest possible quality of a derivation plan. 
Input
The input consists of several test cases. Each test case begins with a line containing the number of truck types, N, 2 <= N <= 2 000. Each of the following N lines of input contains one truck type code (a string of seven lowercase letters). You may assume that the codes uniquely describe the trucks, i.e., no two of these N lines are the same. The input is terminated with zero at the place of number of truck types.
Output
For each test case, your program should output the text "The highest possible quality is 1/Q.", where 1/Q is the quality of the best derivation plan.
Sample Input
4
aaaaaaa
baaaaaa
abaaaaa
aabaaaa
0
Sample Output
The highest possible quality is 1/3.

题意:n个长度为7的字符串,每个字符穿间的‘距离’是其二者不同的字符个数,求1/MST

思路:MST

AC代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<utility>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#define maxn 2005
#define INF 0x3f3f3f3f
#define LL long long
#define ULL unsigned long long
#define mod 1000000007
#define P pair<int,int>
using namespace std;

int n,m,p,sum;
char s[maxn][10];
int d[maxn],v[maxn];
//v[i]: 若已经纳入生成树,则v[i]=1,否则为0
//d[i]:当前已生成树的点的集合内的点 到 其他点的最短距离

int find_dist(int x,int y)
{
    int cnt=0;
    for(int i=0;i<7;++i){
        if(s[x][i]!=s[y][i])
            cnt++;
    }
    return cnt;
}
void prim()
{
    for(int i=1;i<=n;++i){
        d[i] = find_dist(1,i);
        v[i] = 0;
    }
    v[1] = 1;
    for(int i=1;i<=n-m-1;++i){  //循环n次,每次加入一个点,共n个点
        int mi = INF;
        for(int j=1;j<=n;++j){  //找到符合生成树规则的权值最小的边
            if(!v[j] && d[j]<mi){
                mi = d[j];
                p = j;
            }
        }
        v[p] = 1;
        for(int j=1;j<=n;++j){
            if(!v[j] && find_dist(p,j)<d[j])
                d[j] = find_dist(p,j);
        }
    }
    sum = 0;
    for(int i=1;i<=n;++i){
        sum += d[i];
    }
}
int main()
{
    while(scanf("%d",&n)!=EOF&&n){
        getchar();
        memset(v,0,sizeof(v));
        for(int i=1;i<=n;++i){
            scanf("%s",s[i]);
            getchar();
        }
        prim();
        printf("The highest possible quality is 1/%d.\n",sum);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,根据标注数据的格式,可以得到Truck的信息如下: - 类别:Truck - 难易程度:0.00 - 我们假设该车辆的朝向为负y方向,即旋转了-90度,因此旋转角度为-1.57弧度。 - 中心点在图像上的x坐标为599.41,y坐标为156.40,物体的宽度为2.85,高度为2.63,长度为12.34。 - 该车辆的置信度为0.47,视角为1.49弧度,截距为69.44,高度为-1.56。 接下来,我们需要进行坐标系的转换。假设激光雷达坐标系的原点在车辆的重心处,与车辆坐标系重合,且激光雷达坐标系的x、y、z轴分别指向车辆的前、左、上方向,则可以将标注框从相机坐标系转换到激光雷达坐标系的公式如下: ``` P_lidar = R_lidar2cam * P_cam + T_lidar2cam ``` 其中,`P_cam`为在相机坐标系下的标注框的位置,`R_lidar2cam`和`T_lidar2cam`为从相机坐标系到激光雷达坐标系的旋转矩阵和平移向量,可以通过外部标定得到。 假设已经得到了相机坐标系到激光雷达坐标系的旋转矩阵和平移向量: ``` R_lidar2cam = [[0, 0, 1], [-1, 0, 0], [0, -1, 0]] T_lidar2cam = [1.73, 0.0, 1.75] ``` 则可以将标注框从相机坐标系转换到激光雷达坐标系: ``` x_lidar = 0.0 - y_cam y_lidar = -z_cam z_lidar = -x_cam width_lidar = height_cam height_lidar = length_cam length_lidar = width_cam x_lidar += T_lidar2cam[0] y_lidar += T_lidar2cam[1] z_lidar += T_lidar2cam[2] theta_lidar = -np.arctan2(R_lidar2cam[1, 0], R_lidar2cam[0, 0]) - theta_cam ``` 其中,`x_cam`、`y_cam`、`z_cam`、`width_cam`、`height_cam`、`length_cam`、`theta_cam`分别为标注框在相机坐标系下的位置、宽度、高度、长度和旋转角度。将上述计算公式带入Truck的标注数据中,可以得到在激光雷达坐标系下的标签: ``` Truck 0.00 -1.75 599.41 2.85 2.63 12.34 -1.57 ``` 其中,第二列为车辆在激光雷达坐标系下的高度,为-1.75。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值