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.

输入输出样例

输入样例#1:

3 3
1 3 1 2
1 2 1 2
2 3 1 2
输出样例#1:

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的更多相关文章

  1. luogu P3116 [USACO15JAN]会议时间Meeting Time

    题目描述 Bessie and her sister Elsie want to travel from the barn to their favorite field, such that the ...

  2. 洛谷P3116 [USACO15JAN]约会时间Meeting Time

    P3116 [USACO15JAN]约会时间Meeting Time 题目描述 Bessie and her sister Elsie want to travel from the barn to ...

  3. #使用parser获取图片信息,输出Python官网发布的会议时间、名称和地点。

    # !/usr/bin/env/Python3 # - * - coding: utf-8 - * - from html.parser import HTMLParser import urllib ...

  4. 【Luogu】P3116会议时间(拓扑排序,DP)

    题目链接 本题使用拓扑排序来规划DP顺序.设s[i][j]表示i步是否能走到j这个点,e[i][j]表示i步是否能走到j这个点——用第二条路径.因为要满足无后效性和正确性,只有第i个点已经全部更新完毕 ...

  5. OneZero第一次站立会议&Sprint Planning Meeting(2016.3.21)

    会议时间:2016年3月21日 11:40~12:00 会议成员:冉华,张敏,王巍,夏一鸣. 会议目的:列举第一周工作内容,确定第一周工作分配.即挑选出一个Story作为本次迭代完成的目标. 会议内容 ...

  6. 4月17日 (PS:由于时间问题,现在才发,望老师见谅)疯狂猜成语-----第三次站立会议 参会人员:杨霏,袁雪,胡潇丹,郭林林,尹亚男,赵静娜

    疯狂猜成语-----第三次站立会议 参会人员:杨霏,袁雪,胡潇丹,郭林林,尹亚男,赵静娜 会议内容: 组员依次汇报自己的工作进度,并且提出自己在进行任务的过程中遇到的问题,是否解决以及解决办法. 以下 ...

  7. 如何从OutLook正确取得定期会议的时间?(待解决)

    背景: 用Microsoft.Office.Interop.Outlook取得日历项,然后根据业务要求筛选. 现象: 如果是定期会议,使用AppointmentItem.Start/End取得的是该定 ...

  8. [LeetCode] Meeting Rooms 会议室

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

  9. 【Beta】阶段 第三次Daily Scrum Meeting

    每日任务 ·1.本次会议为第三次 Meeting 会议 ·2.本次会议在周三上午9:40召开,会议时间为10分钟 一.今日站立式会议照片 二.每个人的工作(有work item的ID) 三.工作中遇到 ...

随机推荐

  1. sass相关随笔

    安装 下载ruby并且安装 点击这里 打开命令行输入 gem install sass 我使用的是sublime text3 还需要下载三个插件 sass -- 可以帮助你语法高亮 sass buil ...

  2. windows 右键崩溃 解决方法

    [问题描述] 选中一个文件,右键之后无法弹出菜单,最后显示: 资源管理器未响应. [参考方法] https://www.jianshu.com/p/d627c941467a [方法介绍] 1.下载Sh ...

  3. 微信iOS端无法执行jquery on()方法

    微信iOS端无法执行jquery on()方法,click方法可以, 如下代码是不会执行的: $(function(){ $('body').on('click','.cka',function(){ ...

  4. LeetCode Excel Sheet Column Number 表列数

    题意:天啊!我竟然看不懂题意,还去翻别人的代码才懂!给定一个字符串,求该字符串二十六进制的总值. 思路:'A'~'Z'就是1到26,"AA"=26+1=27,"BA&qu ...

  5. COGS 11. 运输问题1

    ★★☆   输入文件:maxflowa.in   输出文件:maxflowa.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述]     一个工厂每天生产若干商品,需运输到 ...

  6. js实现排序去重计算字符次数

    /*去重*/ var arr=[1,4,4,7,3,9,0,3,2,1,"你好","你","你好","你 "]; var ...

  7. Extjs4.1+desktop+SSH2 定义程序入口

    app.js定义程序入口: MainController.js: 加载控制器: 外部组件引用入口loader.js 时间组件 静态变量组件: 引入comm.js index.jsp 验证打印 comm ...

  8. innobackupex实现对MySQL的增量备份与还原

    备份增量备份是基于完整备份的,所以我们需要先做一次完整备份: innobackupex --defaults-file=/etc/my.cnf --user root --password cheng ...

  9. iOS将大文件映射到内存(读取大文件)

    http://blog.csdn.net/xyt243135803/article/details/40995759 在<中国区GPS偏移纠正(适用于Google地图)>一文中曾读取一个7 ...

  10. 【CF739E】Gosha is hunting(WQS二分套WQS二分)

    点此看题面 大致题意: 你有两种捕捉球(分别为\(A\)个和\(B\)个),要捕捉\(n\)个神奇宝贝,第\(i\)个神奇宝贝被第一种球捕捉的概率是\(s1_i\),被第二种球捕捉的概率是\(s2_i ...