最小路径覆盖:Divisibility

本文介绍了一个关于数论的问题——寻找一组数中可以选取的最大数量的数,使得任意两个数之间都不能相互整除。通过匈牙利算法实现最大匹配,进而得出最大独立集的大小。
Divisibility Time Limit:1000MS    Memory Limit:32768KB    64bit IO Format:%I64d & %I64u

Description

As we know,the fzu AekdyCoin is famous of math,especially in the field of number theory.So,many people call him "the descendant of Chen Jingrun",which brings him a good reputation.
AekdyCoin also plays an important role in the ACM_DIY group,many people always ask him questions about number theory.One day,all members urged him to conduct a lesson in the group.The rookie daizhenyang is extremely weak at math,so he is delighted.
However,when AekdyCoin tells us "As we know, some numbers have interesting property. For example, any even number has the property that could be divided by 2.",daizhenyang got confused,for he don't have the concept of divisibility.He asks other people for help,first,he randomizely writes some positive integer numbers,then you have to pick some numbers from the group,the only constraint is that if you choose number a,you can't choose a number divides a or a number divided by a.(to illustrate the concept of divisibility),and you have to choose as many numbers as you can.
Poor daizhenyang does well in neither math nor programming.The responsibility comes to you!
 

Input

An integer t,indicating the number of testcases,
For every case, first a number n indicating daizhenyang has writen n numbers(n<=1000),then n numbers,all in the range of (1...2^63-1).
 

Output

The most number you can choose.
 

Sample Input

     
1 3 1 2 3
 

Sample Output

     
2 Hint: If we choose 2 and 3,one is not divisible by the other,which is the most number you can choose.
 
一开始想错了,想把不能除尽的连一块儿,然后找最长的路径
后来发现这样一来可能有问题,另一方面要找路径的长度貌似不太可行
正确做法是把能除尽的连一块儿,然后找最小覆盖路径的数量

#include <iostream>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

const int MAXN=1010;
int uN,vN;  //u,v数目
int g[MAXN][MAXN];//编号是0~n-1的
int linker[MAXN];//是否有父亲,如果有,父亲是谁
bool used[MAXN]; //在本次dfs中是否在路径中被指过
bool dfs(int u){
    int v;
    for(v=0;v<vN;v++)
        if(g[u][v]&&!used[v]){
            used[v]=true;
            if(linker[v]==-1||dfs(linker[v])){//v没有父亲或v的父亲有其他儿子
                linker[v]=u;
                return true;
            }
        }
    return false;
}

int hungary(){
    int res=0;
    int u;
    memset(linker,-1,sizeof(linker));
    for(u=0;u<uN;u++){
        memset(used,0,sizeof(used));
        if(dfs(u))  res++;
    }
    return res;
}

bool cmp(long long a, long long b){
    return a > b;
}

long long num[1010];

int main(){
    int t;
    int n;
    int i, j;
    scanf("%d", &t);
    while(t --){
        scanf("%d", &n);
        for(i = 0; i < n; i ++){
            scanf("%I64d", &num[i]);
        }
        memset(g, 0, sizeof(g));
        sort(num, num + n, cmp);
//        for(i = 0; i < n; i ++)
//            printf("%I64d ", num[i]);
        uN = n;
        vN = n;
        for(i = 0; i < n ; i ++){
            for(j = i + 1; j < n; j ++){
                if(num[i] % num[j] == 0){
                    g[i][j] = 1;
                }
            }
        }
        int ans = n - hungary();
        printf("%d\n", ans);
    }
    return 0;
}





### 关于安全走廊路径规划的技术实现 #### 安全走廊路径规划概述 安全走廊路径规划是一种用于机器人导航的方法,其核心目标是在复杂环境中找到一条既避开障碍物又满足特定约束条件的安全路径。这种技术通常应用于移动机器人、自动驾驶车辆以及无人机等领域。 #### 基本原理与方法 安全走廊路径规划可以看作是全覆盖路径规划的一个子集或扩展版本[^1]。它不仅关注如何覆盖整个区域,还特别强调在动态环境中的安全性与效率。以下是几种常见的算法和技术: #### 几何建模与拓扑优化 几何建模通过构建虚拟通道来表示可行的空间区域。这些通道被称为“安全走廊”,它们连接起点到终点并绕过已知的静态障碍物。为了提高计算效率,常采用如下策略: - **Voronoi图**:利用 Voronoi 图生成中间节点,并将其作为候选路径的一部分[^2]。 - **可视图(Visibility Graphs)**:基于多边形障碍物边界上的顶点创建网络结构,从而简化搜索过程[^3]。 #### 动态避障机制 当面对实时变化的情况时,传统的静态规划可能无法适应新的挑战。因此引入了一些先进的动态调整手段: - **人工势场法 (Artificial Potential Field)**:定义吸引力指向目标位置而排斥力远离危险源,在两者作用下引导实体沿最优轨迹前进[^4]。 - **D* Lite 或 ARA***:这两种增量式重规划框架允许快速响应局部更新的信息,适合处理频繁变动的地图数据[^5]。 #### 多层混合架构设计 对于更加复杂的场景需求,则可考虑运用分层次的方式来进行综合考量——高层负责全局战略决策;低层专注于具体执行细节。例如: - 高级层面使用栅格地图配合启发式搜索寻找大致方向; - 中间阶段细化过渡区间的衔接关系; - 底部则依赖精确传感器反馈完成最后一步精确定位校正操作[^6]。 ```python def plan_safe_corridor(start, goal, obstacles): """ 计算从 start 到 goal 的安全走廊路径 参数: start(tuple): 起始坐标(x,y) goal(tuple): 终点坐标(x,y) obstacles(list of tuples): [(x1,y1),(x2,y2)...], 表示障碍物的位置 返回值: list: 由一系列连续坐标的列表组成的路径 """ # 初始化参数... # 使用A*或其他合适的算法求解最短路经 path = astar_search(grid_map, heuristic_function, start=start, end=goal) # 对所得结果进一步验证是否符合额外限制条件(比如最小转弯半径等) refined_path = enforce_constraints(path, constraints) return refined_path ``` 上述伪代码展示了基本流程逻辑,实际应用还需结合具体情况做出相应修改完善。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值