codeforces 366D 分类: codeforces ...


很有趣的题啊,首先要知道从 1 开始,只走一条路径到达 n 的数字一定是连续的区间,

先枚举确定答案 L,再通过拓扑排序 DP 计算最大的 R (DP过程中确定无向边的方向),

当然我直接写了一个 SPFA 来更新 DP 值,然后就 AC 了~

SPFA期望复杂度 : O(n+m)

时间复杂度:O(m∗(n+m))


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <iostream>
#include <algorithm>

template<class Num>void read(Num &x)
{
    char c; int flag = 1;
    while((c = getchar()) < '0' || c > '9')
        if(c == '-') flag *= -1;
    x = c - '0';
    while((c = getchar()) >= '0' && c <= '9')
        x = (x<<3) + (x<<1) + (c-'0');
    x *= flag;
    return;
}
template<class Num>void write(Num x)
{
    if(x < 0) putchar('-'), x = -x;
    static char s[20];int sl = 0;
    while(x) s[sl++] = x%10 + '0',x /= 10;
    if(!sl) {putchar('0');return;}
    while(sl) putchar(s[--sl]);
}

const int maxn = 1005, maxm = 3005, INF = 0x3f3f3f3f;

struct Edge
{
    int v, l, r, next;
    Edge(int v = 0,int l = 0,int r = 0,int next = 0):v(v),l(l),r(r),next(next){}
}edge[maxm<<1];

int head[maxn], el;

void NewEdge(int u,int v,int l,int r)
{
    edge[++el] = Edge(v, l, r, head[u]), head[u] = el;
}

int n, m, ans, st;

void init()
{
    int u, v, l, r;

    read(n), read(m);

    for(int i = 1; i <= m; i++)
    {
        read(u), read(v), read(l), read(r);
        NewEdge(u, v, l, r), NewEdge(v, u, l, r);
    }
}
int SPFA(int L)
{
    static int line[maxn], dist[maxn];  
    static bool hash[maxn];

    int f = 0, r = 0;

    for(int i = 1; i <= n; i++) dist[i] = 0;

    dist[1] = INF, line[r] = 1, r = (r + 1)%maxn;
    hash[1] = true;

    while(f != r)
    {
        int x = line[f];
        f = (f + 1)%maxn, hash[x] = false;

        for(int i = head[x]; i; i = edge[i].next)
        {
            if(edge[i].l > L) continue;

            int t = std::min(edge[i].r - L + 1, dist[x]), p = edge[i].v;

            if(t > dist[p])
            {
                dist[p] = t;

                if(!hash[p])
                {
                    if(dist[p] > dist[line[f]])
                        f = (f - 1 + maxn)%maxn, line[f] = p;
                    else
                        line[r] = p, r = (r + 1)%maxn;

                    hash[p] = true;
                }

            }
        }
    }

    return dist[n];
}

int lval[maxm], len;

void solve()
{
    for(int i = 1; i <= m; i++) lval[i] = edge[i<<1].l;

    std::sort(lval + 1, lval + m + 1);  
    len = std::unique(lval + 1, lval + m + 1) - (lval + 1);

    for(int i = 1; i <= len; i++)
        ans = std::max(ans, SPFA(lval[i]));

    if(!ans)
    {
        puts("Nice work, Dima!");
        return;
    }

    write(ans), puts("");
}

int main()
{

    init(), solve();

    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

转载于:https://www.cnblogs.com/dashgua/p/4722947.html

codeforces #366 704B 704C 704D 704E 704C题意:有n个点,第i个点在位置xi,保证对于任意i#include <bits/stdc++.h> using namespace std; #define N 5100 #define ll long long int n,s,e,type; int X[N],a[N],b[N],c[N],d[N]; ll f[N][N]; int main() { scanf("%d%d%d", 阅读详情

相关推荐

Mac新手必看:用Homebrew安装wget的保姆级教程,附常见报错一键修复

本文为Mac新手提供使用Homebrew安装wget的详细教程,涵盖从Homebrew安装到wget基础使用的全流程,并附常见报错一键修复方案。通过本指南,用户可轻松掌握命令行下载工具wget的安装与使用技巧,解决Mac环境下资源下载的各种问题。

weixin_30635053的博客 365

Codeforces 366D Dima and Trap Graph【二分+Dfs】

D. Dima and Trap Graph time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Dima and Inna love spending time together. The

mengxiang000000 444

保姆级教程:在Android车机上从零配置USB Gadget,搞定CarPlay有线连接

本文详细介绍了在Android车机上从零配置USB Gadget以实现CarPlay有线连接的完整实践指南。涵盖内核驱动开发、Android系统配置及用户空间通信架构,帮助开发者深入理解USB子系统和iAP2协议栈,实现稳定可靠的CarPlay有线连接功能。

weixin_30621711的博客 472

codeforces 366D Dima and Trap Graph 题解(搜索+剪枝or二分+枚举)

D. Dima and Trap Graph time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Dima and Inna love spending time tog

K键盘里的青春K 787

避坑指南:中国地面气候日值数据集(V3.0)处理中的常见错误与解决方案

本文详细解析了中国地面气候日值数据集(V3.0)处理中的常见错误与解决方案,包括数据清洗、特征值解码、时间序列处理和质量控制等关键步骤。通过Python实战代码示例,帮助研究者高效处理这一包含全国699个气象站多要素日值数据的数据集,避免常见陷阱,提升气候变化研究和农业气象分析的准确性。

xray4的博客 1025

TPAMI 2025新作LRFormer复现笔记:我的Windows 11 + RTX 4090配置全流程

本文详细记录了在Windows 11系统下使用RTX 4090显卡复现TPAMI 2025顶会论文LRTransformer的完整流程,包括硬件配置、系统优化、Python环境搭建及模型训练中的常见问题解决方案。特别针对Windows平台特有的路径管理、CUDA版本冲突和显存优化等关键技术细节提供了实用指南,帮助开发者高效完成环境搭建和模型训练。

weixin_29094301的博客 411

codeforces Dima and Trap Graph

Dima and Inna love spending time together. The problem is, Seryozha isn’t too enthusiastic to leave his room for some reason. But Dima and Inna love each other so much that they decided to get criminal

黑码 507

SKUA-GOCAD入门教程-第二节

软件启动及项目设置

江洋大葱的博客 1146

codeforces 366D 求1-n点最大区间长度 枚举区间左端+二分区间右端dfs判可行

题意: 给定n个点m条边的无向图 下面m条边 每条边都有一个区间,只有在该区间内的点可以通过   问从1-n点 最长 的一个区间  长度   枚举左端,二分右端,dfs判断是否可行   #include #include #include #include #include #include #include #include using namespace std

九野的博客 2166

[deprecated]第九章:SVM机制: 9-2 Linux HMM原理与实现详解

Linux内核HMM(异构内存管理)子系统为异构计算平台提供统一内存管理机制,支持CPU与GPU等设备共享虚拟地址空间,实现零拷贝数据访问。其核心功能包括:1)统一虚拟地址空间,设备可直接访问CPU进程内存;2)实时页表同步与失效通知,确保地址空间一致性;3)支持设备端page fault处理;4)管理多种内存类型(系统内存、设备私有内存等)。HMM通过mmu_interval_notifier机制感知地址空间变化,提供标准API简化驱动开发,显著提升异构计算性能和数据传输效率。

图形/计算GPU的驱动与虚拟化技术分享园地 2536

进阶06:C#连接TwinCAT 3使用ADS通讯

本文介绍了使用C#通过ADS协议与倍福TwinCAT3 PLC通讯的实现方法。主要内容包括:1)在两台电脑上安装TwinCAT3开发环境并建立网络连接;2)在TwinCAT中定义变量和结构体;3)使用C# Winform开发界面,通过TwinCAT.Ads.dll实现读写功能;4)实现主动读取和通知两种数据获取方式。详细说明了连接建立、变量定义、读写操作及事件通知的实现代码。该方案实现了对PLC寄存器数据的实时监控和操作,为工业控制系统的开发提供了参考。

weixin_38637405的博客 3688

Codeforces 366D Dima and Trap Graph(搜索剪枝/二分)

题目地址:点击打开链接 题意:给你一个图,每条边有一个[L, R],只有在这个区间内的点才能通过,问满足能从1 到n的最大连续区间的长度为多少 思路: 二分思路:枚举下界,二分上界,dfs是否能到。 搜索思路: 剪枝1.如果到过该点,并且此时的左右边界比原先的小,剪枝; 剪枝2:如果当前左右边界范围的值比之前搜到的答案还小,剪枝; 二分代码: #i

CillyB的博客 992

大数据分析利器:Tableau实战教程从入门到精通

你有3家分店,每月收集1000条销售数据(日期、分店、口味、销售额、订单数);想用Excel分析“哪家分店最赚钱”,但要做透视表→改格式→画柱状图,耗时30分钟,还经常因为公式错误返工;想看看“草莓味奶茶的月度销量趋势”,得手动筛选数据、调整折线图轴范围,稍不注意就漏看关键节点;想把分析结果分享给合伙人,Excel表格太抽象,对方盯着数字问“你到底想告诉我什么?

AI架构师小马 1490

Codeforces 366D Dima and Trap Graph 【并查集】

题目链接:Codeforces 366D Dima and Trap Graph D. Dima and Trap Graph time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output Dima and Inna love spend

世界很大 860

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

CodeForces 366D Dima and Trap Graph

D. Dima and Trap Graph time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Dima and Inna love spending time tog

码代码的猿猿 1640

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

codeforces 366D

数学+SPFA

Dash 441

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

【CodeForces】[366A]Dima and Guards

初看题以为是非常麻烦的题 但Special Judge的好处 就是只要满足题意得输出都可以 所以只需要在四个中找出一组满足的输出就好 找不到就输出-1

BoilTask Talk Show 482

codeforces366 语文题

http://codeforces.com/contest/366A题, (看题目看了半小时) 要去女票家,女票家有4个门,每个门有2个守卫,每个守卫可以用巧克力或者果汁去贿赂,我们肯定选一个比较便宜的,我们需要选择一个门走,,, 注意要把钱花光,把钱花光,把钱花光T_T,坑死了#include<cstdio> #include<iostream> #include<algorithm> us

cww97的博客 558

Codeforces 366D 贪心+并查集

最近忙的要死,做作业效率也很低。今天抽了一节水课写了这道上次遗留的题目,不得不说自己实力退步得很厉害,这么简单的题目没有写出来,看来寒假要好好学一下。 回到这道题目,这是一道并查集的题目。 题目大意是:在一个图上有1-n个点,某些点之间连着一些边,每条边上能通过一些数字,有2个信息l和r,代表这条边能通过数字[l,r],题目问你从点1走到点n能顺利通过的数字个数,如果没有数字能从1走到n,则输

CSerxy的专栏 818

codeforces 366D 并查集

//给你一个无向图,图的每条边有一个范围,所选数x要在这个范围能过这条边 //求x最大范围 //枚举所有的边的右边,对于所选右边找左边最小值,用并查集判断是否可行 #include #include #include #include using namespace std ; const int maxn = 1010; int F[maxn] ; int find(int

ijbuhv的专栏 906

Codeforces Round 1004

Codeforces Round 1004

青少年趣味编程 1622

【Codeforces 366D】 Dima and Trap Graph | 并查集、枚举

题目大意: 给出n条路线,每条路线连接x,y ,每条路线覆盖线段[l,r] 询问从1~n的路线中,路线覆盖线段的交集最大 题目思路: 这个题确实是个好题 看了数据范围 又看了提示 才想出来 首先用到了 一个基础思路,枚举最终状态: 考虑最终状态一定是:rj - li 所以可以枚举每一个li作为最终答案的起点,所以如果起点小于当前枚举起点的 与 和 该起点 不相交的线段,都不会被计算 现在只需要知道,现在问题转换为,在枚举的起点作为起点的情况下,是否有合法情况 此时可以用并查集直接判断一.

一只酷酷光儿的博客 464

Codeforces Round #366 (Div. 2)

本来想做一个div2的模拟练习的,结果一不小心做了div1了,感觉div1的A题就有div2的C题难度。 题意: 手机的app有通知,现在有n个app,q个操作。一共有3种操作:1.appX产生一个通知;2.阅读appX的所有通知;3.阅读前t条通知(其中有的通知可能已经读过)。 要点: 就是一个队列模拟,具体解析看下面的代码吧。 #include #include #include #

SeasonJoe的博客 422

CodeForces 366A

Time Limit:1000MS    Memory Limit:262144KB    64bit IO Format:%I64d & %I64u Description Nothing has changed since the last round. Dima and Inna still love each other and want to be togethe

ccutsoft20154954的博客 284

Codeforces 366C Dima and Salad(dp)

题目链接:http://codeforces.com/contest/366/problem/C #include #include #include #include #include #include #include #include #include #include #include #include #include #include using names

llmxby 316
上一篇: hdu 3593 分类: hdu 2015-0...
下一篇: poj 1821 分类: poj 2015-0...
aa288288
博客等级 码龄11年 0粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值