poj_2485 Highways

本文介绍了一道关于寻找图中最小生成树最大边的经典算法题。通过Prim算法实现,确保所有节点相连的同时,最小化最长边的长度。

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

Highways

Time Limit: 1000MS

Memory Limit: 65536K

Total Submissions: 16037

Accepted: 7460

题目链接:http://poj.org/problem?id=2485

Description

The island nation of Flatopiais perfectly flat. Unfortunately, Flatopia has no public highways. So thetraffic is difficult in Flatopia. The Flatopian government is aware of thisproblem. They're planning to build some highways so that it will be possible todrive between any pair of towns without leaving the highway system.

Flatopian towns are numbered from 1 to N. Each highway connects exactly twotowns. All highways follow straight lines. All highways can be used in bothdirections. Highways can freely cross each other, but a driver can only switchbetween highways at a town that is located at the end of both highways.

The Flatopian government wants to minimize the length of the longest highway tobe built. However, they want to guarantee that every town is highway-reachablefrom every other town.

Input

The first line of input is aninteger T, which tells how many test cases followed.
The first line of each case is an integer N (3 <= N <= 500), which is thenumber of villages. Then come N lines, the i-th of which contains N integers,and the j-th of these N integers is the distance (the distance should be aninteger within [1, 65536]) between village i and village j. There is an emptyline after each test case.

Output

For each test case, you shouldoutput a line contains an integer, which is the length of the longest road tobe built such that all the villages are connected, and this value is minimum.

Sample Input

1

3

0 990 692

990 0 179

692 179 0

Sample Output

692

Hint

Huge input,scanf isrecommended.

Source

POJ Contest,Author:Mathematica@ZSU

题意:

给你一张图,让你求最小生成树中最大的边

解题思路:

直接用prim算法来求解即可。

代码:

#include <iostream>
#include<cstdio>
#include<cstring>
#define MAX 503
#define VALUE 0xfffff
using namespace std;

int g[MAX][MAX];
char gra[MAX][7];
int minCost[MAX];
int visited[MAX];

int prim(int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        visited[i]=0;
        minCost[i]=VALUE;
    }
    minCost[0]=0;
   // int res=0;
    int max=0;
    while(true)
    {
        int t=-1;
        for(i=0;i<n;i++)
        {
            if(visited[i]==0 && (t==-1 || minCost[i]<minCost[t]))
            {
                t=i;
            }
        }
        if(t==-1)
            break;
        visited[t]=1;
        if(minCost[t]>max)
        {
            max=minCost[t];
        }
       // res+=minCost[t];
        for(i=0;i<n;i++)
        {
            if(minCost[i]>g[i][t] && g[i][t]!=0)
            {
                minCost[i]=g[i][t];
            }
        }
    }
    return max;
}


int main()
{
    int ts;
    int i,j;
    scanf("%d",&ts);
    while(ts--)
    {
        memset(g,0,sizeof(g));
        int n;
        scanf("%d",&n);
        for(i=0;i<n;i++)
        {
            for(j=0;j<n;j++)
            {
                scanf("%d",&g[i][j]);
            }
        }
        printf("%d\n",prim(n));
    }
    return 0;
}


资源下载链接为: https://pan.quark.cn/s/140386800631 通用大模型文本分类实践的基本原理是,借助大模型自身较强的理解和推理能力,在使用时需在prompt中明确分类任务目标,并详细解释每个类目概念,尤其要突出类目间的差别。 结合in-context learning思想,有效的prompt应包含分类任务介绍及细节、类目概念解释、每个类目对应的例子和待分类文本。但实际应用中,类目和样本较多易导致prompt过长,影响大模型推理效果,因此可先通过向量检索缩小范围,再由大模型做最终决策。 具体方案为:离线时提前配置好每个类目的概念及对应样本;在线时先对给定query进行向量召回,再将召回结果交给大模型决策。 该方法不更新任何模型参数,直接使用开源模型参数。其架构参考GPT-RE并结合相关实践改写,加入上下文学习以提高准确度,还使用BGE作为向量模型,K-BERT提取文本关键词,拼接召回的相似例子作为上下文输入大模型。 代码实现上,大模型用Qwen2-7B-Instruct,Embedding采用bge-base-zh-v1.5,向量库选择milvus。分类主函数的作用是在向量库中召回相似案例,拼接prompt后输入大模型。 结果方面,使用ICL时accuracy达0.94,比bert文本分类的0.98低0.04,错误类别6个,处理时添加“家居”类别,影响不大;不使用ICL时accuracy为0.88,错误58项,可能与未修改prompt有关。 优点是无需训练即可有较好结果,例子优质、类目界限清晰时效果更佳,适合围绕通用大模型api打造工具;缺点是上限不高,仅针对一个分类任务部署大模型不划算,推理速度慢,icl的token使用多,用收费api会有额外开销。 后续可优化的点是利用key-bert提取的关键词,因为核心词语有时比语意更重要。 参考资料包括
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值