JZOI1134 迷宫(maze)
#include <bits/stdc++.h>
#define ll long long
#define INF 2147483647
#define mem_INF 2139062143
#define ll_INF 9223372036854775807
#define eps 1e-8
#define fuckrand() ( ( rand() << 15 ) ^ rand() )
using namespace std;
inline int read() {
int x = 0,tmp = 1;char ch = getchar();
while( ch < '0' || ch > '9' ) {if ( ch == '-' ) tmp = -1; ch = getchar();}
while( ch >= '0' && ch <= '9'){x = x * 10 + ch - '0'; ch = getchar(); }
return x * tmp;
}
struct Node {
int to, next, t, w;
} edge[21000];
bool used[11000];
int N, M, __t__, v;
int head[110], idx = 0, ans_t = __t__, ans_w = 0;
inline void ade( int u, int v, int t, int w ) {
edge[++ idx].to = v;
edge[idx].w = w;
edge[idx].t = t;
edge[idx].next = head[u];
head[u] = idx;
}
inline void add( int u, int v, int t, int w ) {
ade( u, v, t, w );
ade( v, u, t, w );
}
void dfs( int now, int t, int w ) {
if( t > __t__ || w > v ) return;
else if( now == N ) {
if( w < ans_w ) return;
if( w > ans_w ) {
ans_w = w;
ans_t = t;
} else if( w == ans_w ) ans_t = min( t, ans_t );
return;
} else {
for( int i = head[now] ; i != -1 ; i = edge[i].next ) if( !used[( i + 1 ) >> 1] ){
int son = edge[i].to, _t = edge[i].t, _w = edge[i].w;
used[( i + 1 ) >> 1] = 1;
dfs( son, t + _t, w + _w );
used[( i + 1 ) >> 1] = 0;
}
}
}
int main() {
memset( head, -1, sizeof( head ) );
memset( used, 0, sizeof( used ) );
N = read(), M = read(), __t__ = read(), v = read();
for( int i = 1 ; i <= M ; ++ i ) {
int u = read(), v = read(), t = read(), w = read();
ade( u, v, t, w );
ade( v, u, t, w );
}
dfs( 1, 0, 0 );
printf( "%d %d\n", ans_t, v - ans_w );
return 0;
}
--数据点-- | ---N--- | ---Q--- | max{A_x} |
---|---|---|---|
1 | 3 | 3 | 10 |
2 | 10 | 10 | 10000 |
3 | 10 | 10 | 10000 |
4 | 10 | 10000 | 10000 |
5 | 26 | 10000 | 100000000 |
6 | 26 | 10000 | 100000000 |
7 | 26 | 10000 | 1000000000000 |
8 | 26 | 10000 | 10000000000000000 |
9 | 26 | 50000 | 10000000000000000 |
10 | 26 | 100000 | 10000000000000000 |
JZOI1134 迷宫(maze)的更多相关文章
- 迷宫 maze
1 #include <stdlib.h> #include <stdio.h> #define stackinitsize 50 #define stackincrement ...
- 数据结构算法C语言实现(八)--- 3.2栈的应用举例:迷宫求解与表达式求值
一.简介 迷宫求解:类似图的DFS.具体的算法思路可以参考书上的50.51页,不过书上只说了粗略的算法,实现起来还是有很多细节需要注意.大多数只是给了个抽象的名字,甚至参数类型,返回值也没说的很清楚, ...
- golang 实现广度优先算法(走迷宫)
maze.go package main import ( "fmt" "os" ) /** * 广度优先算法 */ /** * 从文件中读取数据 */ fun ...
- php生成迷宫和迷宫寻址算法实例
较之前的终于有所改善.生成迷宫的算法和寻址算法其实是一样.只是一个用了遍历一个用了递归.参考了网上的Mike Gold的算法. <?php //zairwolf z@cot8.com heade ...
- 【noip 模拟赛curse,light,maze】 题解
2018.10.16 总结:考的不好 原因: 1.考的时候没状态,读题读不进去 2.考的时候不仔细,该得分没得到 T1:curse 1.咒语 (curse.pas/c/cpp) [题目描述] 亮亮梦到 ...
- maze writeup
maze writeup 攻防世界的一道迷宫题,第一次接触这样的题,个人感觉很有意思,收获也挺多,做一篇笔记记录一下. 程序分析 __int64 sub_4006B0() { signed __int ...
- [python 译] 基于面向对象的分析和设计
[python 译] 基于面向对象的分析和设计 // */ // ]]> [python 译] 基于面向对象的分析和设计 Table of Contents 1 原文地址 2 引言 2.1 ...
- 面向对象设计——抽象工厂(Abstract Factory)模式
定义 提供一个创建一系列相关或者相互依赖对象的接口,而无需指定它们具体的类.抽象工厂允许客户使用抽象的接口来创建一组相关的产品,而不需要知道或关心实际产出的具体产品是什么.这样一来,客户就能从具体的产 ...
- 设计模式之生成器(Builder)模式
意图 将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以表示不同的表示. 适用性 当创建复杂对象的算法应该独立于该对象的组成部分以及它们的装配方式时. 当构造过程必须允许被构造的对象有不同的表 ...
随机推荐
- 容器————priority_queue
#include <queue> 与queue不同的是可以自定义其中数据的优先级,让优先级高的先出队列. 优先队列具有队列的所有特性,包括基本操作,只是在这基础上添加了内部的一个排序,它本 ...
- bzoj 3881 [Coci2015]Divljak——LCT维护parent树链并
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3881 对 S 建 SAM ,每个 T 会让 S 的 parent 树的链并答案+1:在 T ...
- mysql left join 用法说明
left join中关于where和on条件的几个知识点: 1.多表left join是会生成一张临时表,并返回给用户 2.where条件是针对最后生成的这张临时表进行过滤,过滤掉不符合where条件 ...
- Tomcat负载均衡、调优核心应用进阶学习笔记(三):LNMT nginx+tomcat、LAMT apache+tomcat、session会话保持、不错的站点
文章目录 LNMT nginx+tomcat LAMT apache+tomcat 基于mod_proxy 单节点 配置基于mod_proxy的负载均衡 基于mod_jk(需要编译安装) 单节点 配置 ...
- Linux中grep命令,用或的关系查询多个字符串,正则表达式基础说明
请尊重版权:原文:https://blog.csdn.net/lkforce/article/details/52862193 使用 grep 'word1|word2' 文件名 这样的命令是不对的 ...
- vue-cesium中经纬度写反了,报错
vue-cesium中经纬度写反了,报错 [Vue warn]: Invalid prop: custom validator check failed for prop "position ...
- 洛谷 P2023 维护序列——线段树
先上一波题目 https://www.luogu.org/problem/P2023 复习了一波线段树 题目涉及的操作有区间加 区间乘以及区间求和 tips:线段树在传标记的时候 优先传乘法标记再传加 ...
- 发布 Vant - 高效的 Vue 组件库,再造一个有赞移动商城也不在话下
发布 Vant - 高效的 Vue 组件库,再造一个有赞移动商城也不在话下:https://segmentfault.com/a/1190000011377961 vantUI框架在vue项目中的应用 ...
- Codeforces 488C Fight the Monster
Fight the Monster time limit per test 1 second memory ...
- mac 卸载编辑器卸不干净
Configuration ~/Library/Preferences/ Caches ~/Library/Caches/ Plugins ~/Library/Application Support/ ...