poj3662 Telephone Lines

本文介绍了一种使用二分查找算法解决最优电缆铺设路径的问题。目标是在给定点与边的图中,通过允许一定数量的边免费使用的情况下,寻找连接特定两点的路径,使路径上最贵的电缆成本最小。

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.

Input
* Line 1: Three space-separated integers: N, P, and K
* Lines 2..P+1: Line i+1 contains the three space-separated integers: Ai, Bi, and Li

Output
* Line 1: A single integer, the minimum amount Farmer John can pay. If it is impossible to connect the farm to the phone company, print -1.

Sample Input
5 7 1
1 2 5
3 1 4
2 4 8
3 2 3
5 2 9
3 4 7
4 5 6
Sample Output
4
题意:
给你n个点,m条边,k条可以免费的边。让你从1~n的所有路径中选择一条路径使得删除k条边之后该路径上的最大值最小。
思路:一开始完全没有什么想法,不知道怎么做。然后看了一下别人,瞬间就知道了,原来二分还可以这么用的,因为剩下的图中所有边的最大值越小,删的边相应的就越多,越容易达到k。这样我们可以二分答案(mid)。check的时候对于大于mid的边我们记为边权为1,其余的为0.求一次1~n的最短路之后,看dis[n]是不是小于等于k就可以了。小于等于k说明满足条件,这时让mid减小,否则让mid增加。神奇的二分。

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

using namespace std;
typedef long long LL;
const int MAXN = 1e3+5;
const int inf = 1e9;
int n,m,k;
struct node
{
    int v,w;
    node(int a,int b){v = a; w = b;}
};
vector<node>head[MAXN];


int dis[MAXN];
bool vis[MAXN];
bool check(int mid)
{
    for(int i = 1;i <= n; ++i)
    {
        vis[i] = 0;
        dis[i] = inf;
    }
    deque<int>q;
    int cnt = 1,sum = 0;
    q.push_back(1);
    dis[1] = 0;
    while(!q.empty())
    {
        int u = q.front();
        q.pop_front();
        if(dis[u]*cnt > sum)
        {
            q.push_back(u);
            continue;
        }
        vis[u] = 0;
        cnt--,sum -= dis[u];
        for(int i = 0,l = head[u].size(); i < l; ++i)
        {
            int v = head[u][i].v;
            int w = head[u][i].w;
            w = w>mid?1:0;
            if(dis[v] > dis[u] + w)
            {
                dis[v] = dis[u] + w;
                if(!vis[v])
                {
                    vis[v] = 1;
                    cnt++,sum += dis[v];
                    if(q.empty() || dis[v] < dis[q.front()])q.push_front(v);
                    else q.push_back(v);
                }
            }
        }
    }
    if(dis[n] <= k)return 1;
    return 0;
}



int main()
{
    scanf("%d%d%d",&n,&m,&k);
    int u,v,w;
    for(int i = 0; i < m; ++i)
    {
        scanf("%d%d%d",&u,&v,&w);
        head[u].push_back(node(v,w));
        head[v].push_back(node(u,w));
    }
    int low = 0,high = 1000000;
    int ans = -1,mid;
    while(low <= high)
    {
        mid = (low+high)>>1;
        if(check(mid))
        {
            ans = mid;
            high = mid - 1;
        }
        else low = mid + 1;
    }
    printf("%d\n",ans);
    return 0;
}
内容概要:本文详细记录了对一个Android ARM64静态ELF文件中字符串加密机制的逆向分析过程。该ELF文件的所有字符串均被加密,无法通过常规strings命令或IDA直接识别。作者通过分析发现,加密字符串存储在.rodata段,其解密所需信息(包括密文地址、长度和16位密钥)保存在.data.rel.ro段的40字节描述符中。核心解密函数sub_10F408采用自反的双pass流密码算法,结合固定密钥KEY_TERM(由.data段24字节数据计算得出),实现字节级非线性、位置长度相关的加密。文章还复现了完整的Python解密脚本,并揭示了该保护机制的本质为代码混淆而非强加密,最终成功批量解密全部956条字符串,暴露程序真实行为,如shell命令模板、设备标识篡改、网络重置等操作。此外,文中还提及未启用的自定义壳框架及其反dump设计。; 适合人群:具备逆向工程基础的安全研究人员、二进制分析人员及对ELF保护技术感兴趣的开发者。; 使用场景及目标:①学习ELF二进制中字符串加密的典型实现方式逆向突破口;②掌握从结构识别、函数追踪到算法还原的完整逆向流程;③理解“绑定二进制”的完整性校验设计及其局限性;④实践编写IDAPython脚本自动化提取解密敏感数据。; 阅读建议:此资源以实战案例驱动,不仅展示技术细节,更强调逆向思维验证方法,建议读者结合IDA调试环境,逐步跟随文中步骤进行动态分析算法验证,深入理解每一步的推理依据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值