当前位置: 首页 > news >正文

[POI2009]WIE-Hexer

题目描述

Byteasar has become a hexer - a conqueror of monsters.

Currently he is to return to his hometown Byteburg. The way home, alas, leads through a land full of beasts. Fortunately the habitants, forced to fight the monsters for centuries, have mastered the art of blacksmithery - they are now capable of making special swords that are very efficient against the beasts.

The land Byteasar wanders through is quite vast: many towns lie there, and many roads connect them.

These roads do not cross outside the towns (mostly because some of them are underground passages).

Byteasar has gathered all practical information about the land (all hexers like to know these things).

He knows what kind of monsters he may come across each of the roads and how much time he needs to walk it down.

He also knows in which villages there are blacksmiths and against what kinds of monsters the swords that they make work.

Byteasar wants to get back to Byteburg as soon as possible.

As a hexer he is quite ashamed that he does not know the best route, and that he has no sword on him at the moment.

Help him find the shortest path to Byteburg such that whenever he could meet some king of monster, previously he would have a chance to get an appropriate sword to fight the beast.

You need not worry about the number or weight of the swords - every hexer is as strong as an ox, so he can carry (virtually) unlimited number of equipment, swords in particular.

大陆上有n个村庄,m条双向道路,p种怪物,k个铁匠,每个铁匠会居住在一个村庄里,你到了那个村庄后可以让他给你打造剑,每个铁匠打造的剑都可以对付一些特定种类的怪物,每条道路上都可能出现一些特定种类的怪物,每条道路都有一个通过所需要的时间,现在要从1走到n,初始的时候你没有剑,要求在经过一条道路的时候,对于任意一种可能出现在这条道路上的的怪物,你都有已经有至少一把剑可以对付他,求从1走到n的最短时间(打造剑不需要时间)

输入输出格式

输入格式:

 

The first line of the standard input holds four integers: n,m,p,kn,m,p,k (1\le n\le 200,0\le m\le 3000,1\le p\le 13,0\le k\le n1n200,0m3000,1p13,0kn),separated by single spaces, that denote respectively:

the number of towns, the number of roads connecting them,the number of different kinds of monsters and the number of blacksmiths.

The towns are numbered from 11 to nn in such a way that nn is Byteburg's number and 11 is the number of the village which Byteasar starts in. The monster kinds are numbered from 11 to pp.

In the following kk lines the profiles of successive blacksmiths are given,one per line. The (i+1)(i+1)-st line holds the integers w_i,q_i,r_{i,1}<r_{i,2}<...<r_{i,q_i}wi,qi,ri,1<ri,2<...<ri,qi(1\le w_i\le n,1\le q_i\le p,1\le r_{i,j}\le p1win,1qip,1ri,jp),separated by single spaces, that denote respectively: the number of town in which the blacksmith lives, the number of different kinds of monsters against which his swords are efficient, and the kinds of monsters themselves (in increasing order). Note that a town may have more than one blacksmith.

Then mm lines with roads' descriptions follow.The (k+i+1)(k+i+1)-th line holds the integersv_i,w_i,t_i,s_i,u_{i,1}<u_{i,2}<...<u_{i,s_i}vi,wi,ti,si,ui,1<ui,2<...<ui,si(1\le v_i<w_i\le n,1\le t_i\le 500,0\le s_i\le p,1\le u_{i,j}\le p1vi<win,1ti500,0sip,1ui,jp)separated by single spaces, that denote respectively: the towns that the road connects, the time needed to walk down the road (same in both directions), the number of different kinds of monsters that may appear on that road, and finally the kinds of monsters themselves (in increasing order). No two roads connect the same pair of towns.

 

输出格式:

 

Your programme is to print out one integer to the standard output - the minimum summary time required to reach Byteburg.

Should reaching Byteburg be impossible, the number should be -11.

 

输入输出样例

输入样例#1:  复制
6 7 4 2
2 1 2
3 2 1 3
1 2 2 0
2 3 9 0
1 4 2 1 2
2 5 3 0
4 5 5 2 2 3
4 6 18 0
5 6 3 2 1 2
输出样例#1:  复制
24

说明

大陆上有n个村庄,m条双向道路,p种怪物,k个铁匠,每个铁匠会居住在一个村庄里,你到了那个村庄后可以让他给你打造剑,每个铁匠打造的剑都可以对付一些特定种类的怪物,每条道路上都可能出现一些特定种类的怪物,每条道路都有一个通过所需要的时间,现在要从1走到n,初始的时候你没有剑,要求在经过一条道路的时候,对于任意一种可能出现在这条道路上的的怪物,你都有已经有至少一把剑可以对付他,求从1走到n的最短时间(打造剑不需要时间)

 

分析:

可怜的洛谷就一道dijkstra题目,于是我只能做这题了。。。

根据某题解大佬的讲法:“观察数据,发现p<=13,n<=200,所有我们很明显可以将状态保存下来。”

WOC!那么“根据dijkstra的性质,n第一次被取出时就是答案。”

于是我就会做了。。。

 

CODE(还是看大佬的代码吧,我的代码。。。不忍直视。。。):

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<string>
 5 #include<cstring>
 6 #include<cmath>
 7 #include<queue>
 8 using namespace std;
 9 const int N=2e2+10,M=3e3+10,inf=1e9;
10 int n,m,k,p,tot,a[N],d[N][N*50],vis[N][N*50];
11 int head[N],next[M*2],ver[M*2],edge[M*2],cost[M*2];
12 priority_queue<pair<pair<int,int>,int> >q;
13 inline int read(){
14     int x=0,f=1;char ch=getchar();
15     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
16     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
17     return x*f;
18 }
19 inline void add(int x,int y,int z,int c){
20     ver[++tot]=y;edge[tot]=z;cost[tot]=c;next[tot]=head[x];head[x]=tot;
21 }
22 inline int dijkstra(){
23     for(int i=1;i<=n;i++){
24         for(int j=0;j<(1<<p);j++) d[i][j]=inf;
25     }
26     d[1][0]=0;q.push(make_pair(make_pair(0,1),0));
27     while(q.size()){
28         int t=-q.top().first.first,x=q.top().first.second,s=q.top().second;q.pop();
29         if(x==n) return t; 
30         if(vis[x][s]) continue;
31         vis[x][s]=1;s|=a[x];
32         for(int i=head[x];i;i=next[i]){
33             int y=ver[i],z=edge[i],c=cost[i];
34             if((s|c)!=s) continue;
35             if(d[y][s]>t+edge[i]){
36                 d[y][s]=t+edge[i];
37                 q.push(make_pair(make_pair(-d[y][s],y),s));
38             }
39         }
40     }
41     return -1;
42 }
43 int main(){
44     n=read();m=read();p=read();k=read();
45     for(int i=1;i<=k;i++){
46         int w=read(),q=read();
47         for(int j=1;j<=q;j++){
48             int x=read();a[w]|=1<<(x-1);
49         }
50     }
51     for(int i=1;i<=m;i++){
52         int x=read(),y=read(),z=read(),s=read(),c=0;
53         for(int j=1;j<=s;j++){
54             int v=read();c|=1<<(v-1);
55         }
56         add(x,y,z,c);add(y,x,z,c);
57     }
58     printf("%d\n",dijkstra());
59     return 0;
60 }

 

转载于:https://www.cnblogs.com/kanchuang/p/11150350.html

相关文章:

  • ~~函数基础(三):嵌套函数匿名函数~~
  • YYImage渲染流程+源码分析
  • 我们是否应该使用 Set 来提高代码的性能
  • Nginx配置upstream实现负载均衡
  • nginx实现请求转发
  • 【模板】单源最短路径(标准版)
  • Python3 数据类型-集合
  • 居民运输问题得到根本改善
  • 集群、分布式、负载均衡区别
  • 什么是自动化测试以及环境搭建
  • HashSet的实现原理
  • DELPHI 线程类(转,自己参考,版权归原作者)
  • WCF笔记
  • IE 6下测试有scriptManager控件的页面,内存不断增长
  • elementUI 弹出框添加可自定义拖拽和拉伸功能,并处理边界问题
  • Android Volley源码解析
  • C# 免费离线人脸识别 2.0 Demo
  • Javascript基础之Array数组API
  • laravel 用artisan创建自己的模板
  • Linux Process Manage
  • Linux快速配置 VIM 实现语法高亮 补全 缩进等功能
  • Python学习之路13-记分
  • 分布式熔断降级平台aegis
  • 批量截取pdf文件
  • 网页视频流m3u8/ts视频下载
  • 问:在指定的JSON数据中(最外层是数组)根据指定条件拿到匹配到的结果
  • 小程序 setData 学问多
  • 鱼骨图 - 如何绘制?
  • hi-nginx-1.3.4编译安装
  • python最赚钱的4个方向,你最心动的是哪个?
  • 好程序员大数据教程Hadoop全分布安装(非HA)
  • ​2021半年盘点,不想你错过的重磅新书
  • # 执行时间 统计mysql_一文说尽 MySQL 优化原理
  • #微信小程序:微信小程序常见的配置传值
  • $(selector).each()和$.each()的区别
  • (2/2) 为了理解 UWP 的启动流程,我从零开始创建了一个 UWP 程序
  • (搬运以学习)flask 上下文的实现
  • (草履虫都可以看懂的)PyQt子窗口向主窗口传递参数,主窗口接收子窗口信号、参数。
  • (转)视频码率,帧率和分辨率的联系与区别
  • *setTimeout实现text输入在用户停顿时才调用事件!*
  • .mysql secret在哪_MYSQL基本操作(上)
  • .NET 读取 JSON格式的数据
  • .net2005怎么读string形的xml,不是xml文件。
  • .NET程序员迈向卓越的必由之路
  • @JsonFormat与@DateTimeFormat注解的使用
  • @JsonSerialize注解的使用
  • @KafkaListener注解详解(一)| 常用参数详解
  • []利用定点式具实现:文件读取,完成不同进制之间的
  • [<MySQL优化总结>]
  • [8-23]知识梳理:文件系统、Bash基础特性、目录管理、文件管理、文本查看编辑处理...
  • [AI]ChatGPT4 与 ChatGPT3.5 区别有多大
  • [CERC2017]Cumulative Code
  • [CF482B]Interesting Array
  • [codeforces]Levko and Permutation
  • [CSS]中子元素在父元素中居中