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. Java开发工具IntelliJ IDEA本地历史记录的使用方法

    IntelliJ IDEA的本地历史记录可以帮助用户记录并跟踪本地项目的更改,防止项目的意外丢失或来源于IDE之外的项目更改.本教程将展示如何使用本地历史记录查看和恢复某些项目更改. 1 .从头开始创 ...

  2. CAD Import .NET支持AutoCAD DWG 2013

    CADSoftTools发布了CAD Import .NET 9一个新版本.NET开发库,可以提供给开发人员导入AutoCAD DWG.DXF.HPGL.PLT.CGM等格式的功能. 在新版本中,CA ...

  3. [WPF][ListBox]鼠标拖拽多选,(Shift Key、Ctrl Key多选有效)(转)

    <ListBox Name="listBox" SelectionMode="Extended"> <ListBox.Resources> ...

  4. hadoop启动中缺少datanode

    原文链接地址:https://blog.csdn.net/islotus/article/details/78357857 本人测试有效: 首先删除hadoop下的dfs文件(注:本文件不一定在had ...

  5. LeetCode Single Number III (xor)

    题意: 给一个数组,其中仅有两个元素是出现1次的,且其他元素均出现2次.求这两个特殊的元素? 思路: 跟查找单个特殊的那道题是差不多的,只是这次出现了两个特殊的.将数组扫一遍求全部元素的异或和 x,结 ...

  6. php使用GD库实现图片水印和缩略图——生成图片缩略图

    今天呢,就来学习一下在php中使用PD库来实现对图片水印的文字水印方法,不需要PS哦! 首先,准备素材 (1)准备一张图片 (2)准备一张水印(最好是透明的,即背景是白色底) (3)准备一中字体(在电 ...

  7. 传入指定字段名称就可以排序的EF写法

    private static IQueryable<T> SetQueryableOrder<T>(this IQueryable<T> query, string ...

  8. ubuntu or centos 网卡无法启动

    [root@seasoned-bro:/home/daeh0f]# /etc/init.d/network restart Restarting network (via systemctl): Jo ...

  9. python剑指offer 实现树的子结构

    题目描述 输入两棵二叉树A,B,判断B是不是A的子结构.(ps:我们约定空树不是任意一个树的子结构) # -*- coding:utf-8 -*- # class TreeNode: # def __ ...

  10. VS Code 用户自定义代码片段(React)

    VS Code 用户自定义代码片段(React) .jsxReact组件模板:javascriptreact.json { "Import React": { "pref ...