POJ 3662 Telephone Lines

本文解决了一个复杂的图论问题,即如何在N个电话杆间通过最少的成本连接农场与电话网络。利用二分查找与SPFA算法,寻找1到N路径上最长边的最小值,并考虑选择K条边权重为0的可能性。

Description

Farmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is uncooperative, so he needs to pay for some of the cables required to connect his farm to the phone system.

There are N (1 ≤ N ≤ 1,000) forlorn telephone poles conveniently numbered 1..N that are scattered around Farmer John's property; no cables connect any them. A total of P (1 ≤ P ≤ 10,000) pairs of poles can be connected by a cable; the rest are too far apart.

The i-th cable can connect the two distinct poles Ai and Bi, with length Li (1 ≤ Li ≤ 1,000,000) units if used. The input data set never names any {Ai, Bi} pair more than once. Pole 1 is already connected to the phone system, and pole N is at the farm. Poles 1 and N need to be connected by a path of cables; the rest of the poles might be used or might not be used.

As it turns out, the phone company is willing to provide Farmer John with K (0 ≤ K < N) lengths of cable for free. Beyond that he will have to pay a price equal to the length of the longest remaining cable he requires (each pair of poles is connected with a separate cable), or 0 if he does not need any additional cables.

Determine the minimum amount that Farmer John must pay.

题目大意:N的点M条边的图,求1到n路径中最长边的最小值,并且可以选择K条边权值变为0

解题报告:显然是需要二分答案的,那么建图之后我们就开始跑spfa,spfa的状态定义为到i点最少需要几条边免费,如果跑出来的值>K 那么就不合法,参考模型:通往奥格瑞玛的路

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define RG register
#define il inline
#define iter iterator
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
const int N=1005,M=10005,inf=1000000;
int n,m,K,head[N],num=0,nxt[M<<1],to[M<<1],dis[M<<1];
void link(int x,int y,int z){
    nxt[++num]=head[x];to[num]=y;dis[num]=z;head[x]=num;
}
int f[N],q[N*10],mod=N*10;bool vis[N];
bool check(int mid){
    int t=0,sum=1,x,u,v;
    for(int i=0;i<=n;i++)f[i]=inf,vis[i]=false;
    f[1]=0;vis[1]=true;q[1]=1;
    while(t!=sum){
        t++;if(t==mod)t=0;x=q[t];
        for(int i=head[x];i;i=nxt[i]){
            u=to[i];
            v=dis[i]<=mid?0:1;
            if(f[x]+v<f[u]){
                f[u]=f[x]+v;
                if(!vis[u]){
                    vis[u]=true;
                    sum++;if(sum==mod)sum=0;q[sum]=u;
                }
            }
        }
        vis[x]=false;
    }
    return f[n]<=K;
}
void work()
{
    int x,y,z;
    scanf("%d%d%d",&n,&m,&K);
    for(int i=1;i<=m;i++){
        scanf("%d%d%d",&x,&y,&z);
        link(x,y,z);link(y,x,z);
    }
    int l=0,r=inf,mid,ans=-1;
    while(l<=r){
        mid=(l+r)>>1;
        if(check(mid))ans=mid,r=mid-1;
        else l=mid+1;
    }
    printf("%d\n",ans);
}

int main()
{
    work();
    return 0;
}

转载于:https://www.cnblogs.com/Yuzao/p/7498579.html

一、数据采集层:多源人脸数据获取 该层负责从不同设备 / 渠道采集人脸原始数据,为后续模型训练与识别提供基础样本,核心功能包括: 1. 多设备适配采集 实时摄像头采集: 调用计算机内置摄像头(或外接 USB 摄像头),通过OpenCV的VideoCapture接口实时捕获视频流,支持手动触发 “拍照”(按指定快捷键如Space)或自动定时采集(如每 2 秒采集 1 张),采集时自动框选人脸区域(通过Haar级联分类器初步定位),确保样本聚焦人脸。 支持采集参数配置:可设置采集分辨率(如 640×480、1280×720)、图像格式(JPG/PNG)、单用户采集数量(如默认采集 20 张,确保样本多样性),采集过程中实时显示 “已采集数量 / 目标数量”,避免样本不足。 本地图像 / 视频导入: 支持批量导入本地人脸图像文件(支持 JPG、PNG、BMP 格式),自动过滤非图像文件;导入视频文件(MP4、AVI 格式)时,可按 “固定帧间隔”(如每 10 帧提取 1 张图像)或 “手动选择帧” 提取人脸样本,适用于无实时摄像头场景。 数据集对接: 支持接入公开人脸数据集(如 LFW、ORL),通过预设脚本自动读取数据集目录结构(按 “用户 ID - 样本图像” 分类),快速构建训练样本库,无需手动采集,降低系统开发与测试成本。 2. 采集过程辅助功能 人脸有效性校验:采集时通过OpenCV的Haar级联分类器(或MTCNN轻量级模型)实时检测图像中是否包含人脸,若未检测到人脸(如遮挡、侧脸角度过大),则弹窗提示 “未识别到人脸,请调整姿态”,避免无效样本存入。 样本标签管理:采集时需为每个样本绑定 “用户标签”(如姓名、ID 号),支持手动输入标签或从 Excel 名单批量导入标签(按 “标签 - 采集数量” 对应),采集完成后自动按 “标签 - 序号” 命名文件(如 “张三
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值