P3116 [USACO15JAN]会议时间Meeting Time
P3116 [USACO15JAN]会议时间Meeting Time
题目描述
Bessie and her sister Elsie want to travel from the barn to their favorite field, such that they leave at exactly the same time from the barn, and also arrive at exactly the same time at their favorite field.
The farm is a collection of N fields (1 <= N <= 100) numbered 1..N, where field 1 contains the barn and field N is the favorite field. The farm is built on the side of a hill, with field X being higher in elevation than field Y if X < Y. An assortment of M paths connect pairs of fields. However, since each path is rather steep, it can only be followed in a downhill direction. For example, a path
connecting field 5 with field 8 could be followed in the 5 -> 8 direction but not the other way, since this would be uphill. Each pair of fields is connected by at most one path, so M <= N(N-1)/2.
It might take Bessie and Elsie different amounts of time to follow a path; for example, Bessie might take 10 units of time, and Elsie 20. Moreover, Bessie and Elsie only consume time when traveling on paths between fields -- since they are in a hurry, they always travel through a field in essentially zero time, never waiting around anywhere.
Please help determine the shortest amount of time Bessie and Elsie must take in order to reach their favorite field at exactly the same moment.
给出一个n个点m条边的有向无环图,每条边两个边权。
n<=100,没有重边。
然后要求两条长度相同且尽量短的路径,
路径1采用第一种边权,路径2采用第二种边权。
没有则输出”IMPOSSIBLE”
输入输出格式
输入格式:
INPUT: (file meeting.in)
The first input line contains N and M, separated by a space.
Each of the following M lines describes a path using four integers A B C D, where A and B (with A < B) are the fields connected by the path, C is the time required for Bessie to follow the path, and D is the time required for Elsie to follow the path. Both C and D are in the range 1..100.
输出格式:
OUTPUT (file meeting.out)
A single integer, giving the minimum time required for Bessie and
Elsie to travel to their favorite field and arrive at the same moment.
If this is impossible, or if there is no way for Bessie or Elsie to reach
the favorite field at all, output the word IMPOSSIBLE on a single line.
输入输出样例
3 3
1 3 1 2
1 2 1 2
2 3 1 2
2
说明
SOLUTION NOTES:
Bessie is twice as fast as Elsie on each path, but if Bessie takes the
path 1->2->3 and Elsie takes the path 1->3 they will arrive at the
same time.
分析
这道题可以用动规做,f[i][j]表示经过长度为j的路径能否到达i点,g[][]数组同理,只不过是题目中的第二组数据。
然后我们会用到拓扑,为什么用拓扑呢?因为要满足动规的无后效性,必须要用已经完成(没有点可以在更改当他的值,即没有边在通向他)的点,这一点很重要!!!
但是一件惊人的件事情:不用拓扑居然也可能过!!!你在逗我吗?提交代码时写错了个地方,代码第28行的ru[b]++忘记写了,就交了,然后呢,就A了,,,。。。
没加28行,意味着说有的点会按顺序加入队列中,然后相当于枚举了所有的点一遍而已,也就没用到拓扑。数据也没这么弱的吧!!!
注意:46行不能有等号,数组最大是MAXE-1,不然会RE!
代码
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std; const int MAXN = ;
const int MAXE = ;
struct Edge{
int to,nxt,w1,w2;
}e[MAXE];
bool f[MAXN][MAXE],g[MAXN][MAXE],vis[MAXN];
int head[MAXN],ru[MAXN];
int n,m,tot;
queue<int>q; int main()
{
scanf("%d%d",&n,&m);
for (int x,y,a,b,i=; i<=m; ++i)
{
scanf("%d%d%d%d",&a,&b,&x,&y);
e[++tot].nxt = head[a]; //建边
e[tot].to = b;
e[tot].w1 = x;
e[tot].w2 = y;
head[a] = tot;
++ru[b];
}
for (int i=; i<=n; ++i) //拓扑
if (!ru[i]) q.push(i);
f[][] = g[][] = true;
while (!q.empty())
{
int u = q.front();
q.pop();
for (int i=head[u]; i; i=e[i].nxt)
{
int w1 = e[i].w1, w2 = e[i].w2, v = e[i].to;
for (int j=; j+w1<MAXE; ++j) f[v][j+w1] |= f[u][j];
for (int j=; j+w2<MAXE; ++j) g[v][j+w2] |= g[u][j];
ru[v]--;
if (!ru[v]) q.push(v);
}
}
for (int i=; i<MAXE; ++i)
if (f[n][i]&&g[n][i]){ printf("%d",i); return ; }
printf("IMPOSSIBLE");
return ;
}
P3116 [USACO15JAN]会议时间Meeting Time的更多相关文章
- luogu P3116 [USACO15JAN]会议时间Meeting Time
题目描述 Bessie and her sister Elsie want to travel from the barn to their favorite field, such that the ...
- 洛谷P3116 [USACO15JAN]约会时间Meeting Time
P3116 [USACO15JAN]约会时间Meeting Time 题目描述 Bessie and her sister Elsie want to travel from the barn to ...
- #使用parser获取图片信息,输出Python官网发布的会议时间、名称和地点。
# !/usr/bin/env/Python3 # - * - coding: utf-8 - * - from html.parser import HTMLParser import urllib ...
- 【Luogu】P3116会议时间(拓扑排序,DP)
题目链接 本题使用拓扑排序来规划DP顺序.设s[i][j]表示i步是否能走到j这个点,e[i][j]表示i步是否能走到j这个点——用第二条路径.因为要满足无后效性和正确性,只有第i个点已经全部更新完毕 ...
- OneZero第一次站立会议&Sprint Planning Meeting(2016.3.21)
会议时间:2016年3月21日 11:40~12:00 会议成员:冉华,张敏,王巍,夏一鸣. 会议目的:列举第一周工作内容,确定第一周工作分配.即挑选出一个Story作为本次迭代完成的目标. 会议内容 ...
- 4月17日 (PS:由于时间问题,现在才发,望老师见谅)疯狂猜成语-----第三次站立会议 参会人员:杨霏,袁雪,胡潇丹,郭林林,尹亚男,赵静娜
疯狂猜成语-----第三次站立会议 参会人员:杨霏,袁雪,胡潇丹,郭林林,尹亚男,赵静娜 会议内容: 组员依次汇报自己的工作进度,并且提出自己在进行任务的过程中遇到的问题,是否解决以及解决办法. 以下 ...
- 如何从OutLook正确取得定期会议的时间?(待解决)
背景: 用Microsoft.Office.Interop.Outlook取得日历项,然后根据业务要求筛选. 现象: 如果是定期会议,使用AppointmentItem.Start/End取得的是该定 ...
- [LeetCode] Meeting Rooms 会议室
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...
- 【Beta】阶段 第三次Daily Scrum Meeting
每日任务 ·1.本次会议为第三次 Meeting 会议 ·2.本次会议在周三上午9:40召开,会议时间为10分钟 一.今日站立式会议照片 二.每个人的工作(有work item的ID) 三.工作中遇到 ...
随机推荐
- python_3 :用python微信跳一跳
[学习使用他人代码] 2018年01月21日 19:29:02 独行侠的守望 阅读数:319更多 个人分类: Python 编辑 版权声明:本文为博主原创文章,转载请注明文章链接. https://b ...
- 什么是SpringBoot
随着动态语言的流行(Ruby,Groovy,Scala,Node.js),Java的开发显得格外的笨重;繁多的配置,低下的开发效率,复杂的部署流程以及第三方技术集成难度大. 在上述环境 下,Sprin ...
- 微信小程序时间处理问题
环境: 开发环境: 1. Mac OS 10.12.5 2. 微信Web开发者工具 v0.18.182200 测试环境: 1. iPhone 7 2. iOS 10.3.2 3. 微信 6.5.9 问 ...
- SVG矢量图【转】
var iconArray=[ //'circle', //实心圆 //'rect', //矩形 //'roundRect', //圆角矩形 //'triangle', //三角形 //'diamon ...
- thinkphp 3.2.3版本学习笔记
2.开启调试模式,有什么作用?(默认关闭,在ThinkPHP.php 33行左右) (1)非法调用的时候,有详细的报错信息,便于调试 (2)APP_DEBUG为true并且缓存文件存在,走缓存文件,否 ...
- 干净的架构The Clean Architecture_软件架构系列
本文转载自:https://www.jdon.com/artichect/the-clean-architecture.html ,这个博客站很有历史了,博主经常翻译Github大牛的文章,值得墙裂推 ...
- arr.forEach()与for...in的用法举例
1.forEach() 将给定的数字转换成罗马数字. 所有返回的 罗马数字 都应该是大写形式. function convert(num) { var str = ""; var ...
- 第17题:打印1到最大的n位数
面试题17:打印1到最大的n位数 题目:输入数字n,按顺序打印出从1最大的n位十进制数.比如输入3,则打印出1.2.3一直到最大的3位数即999. 考点: 用字符串或者数组表达一个大数. 思路 1. ...
- ORTP-0.27.0移植
注意: a. 对于0.27一下版本的ORTP的交叉编译则没有一下依赖库 b. 交叉编译工具链是: arm-linux-gnueabihf-gcc-4.9.1 (4.9版本一下的编译bctoolbox出 ...
- 1048: [HAOI2007]分割矩阵
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1184 Solved: 863[Submit][Status][Discuss] Descripti ...