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) 三.工作中遇到 ...
随机推荐
- 阐述简称PO,VO,TO,BO,DAO,POJO
PO(persistant object) 持久对象 在o/r映射的时候出现的概念,如果没有o/r映射,没有这个概念存在了.通常对应数据模型(数据库),本身还有部分业务逻辑的处理.可以看成是与数据库中 ...
- linux 修改myql 编码配置等信息参考
mysql 配置: 1:编辑配置文件: vi /etc/my.cnf 2:修改配置如下: [client] password = 123456 port = 330 ...
- 超链接显示网站 A,访问后进入网站 B
#前端黑魔法# 出一个思考题:如何用最少的字符实现下图效果.即超链接显示网站 A,访问后进入网站 B. 当然这个是上古时代的黑魔法了,稍懂前端的都知道原理.所以这里只问最短的实现~ 一个简单的演示:( ...
- bank conflct 一句话总结
由于最新的多播模式区别于原来的广播模式,原来同一个warp不同线程访问同一个bank的相同地址不再是bank conflict, 现在总结为:只要同一个 warp 的不同线程会访问到同一个 bank ...
- 《Python高效开发实战》实战演练——开发Django站点1
6.2 实战演练:开发Django站点 用Django开发网站需要遵循Django的一套开发流程.本节通过建立一个消息录入页面演示Django的开发流程及相关技术. 6.12.1 建立项目 在进行D ...
- LeetCode ZigZag Conversion(将字符串排成z字型)
class Solution { public: string convert(string s, int nRows) { string a=""; int len=s.leng ...
- 如何在SAP Server Side JavaScript里消费destination
在SAP云平台里打开SAP HANA Web-Based Development Workbench进行服务器端JavaScript的开发. 创建一个新的package: 创建一个新的applicat ...
- IOS 当一个控件被添加到父控件中会调用(didMoveToSuperview)
/** * 当一个控件被添加到父控件中就会调用 */ - (void)didMoveToSuperview { if (self.group.opened) { self.nameView.image ...
- 【洛谷1120】小木棍(一道有技巧的dfs)
点此看题面 大致题意: 给你\(N\)根小木棍,请你把它们拼成若干根长度相同的木棍,问你最小可能长度. 枚举+\(dfs\) 显然的,木棍的长度肯定是\(\sum_{i=1}^n len[i]\)的一 ...
- 2018.10.24 NOIP2018模拟赛 解题报告
得分: \(100+0+100=200\)(\(T2\)悲惨爆\(0\)) \(P.S.\)由于原题是图片,所以我没有上传题目描述,只有数据. \(T1\):query(点此看题面) 熟悉主席树的人都 ...