zoukankan      html  css  js  c++  java
  • bzoj3890 [Usaco2015 Jan]Meeting Time

    Description

    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

    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

    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.

    Sample Input

    3 3
    1 3 1 2
    1 2 1 2
    2 3 1 2

    Sample Output

    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]、g[i][j]表示用第一种/第二种边权到达i号点,当前费用为j的状态是否存在
    这样i是100的,因为边权100所以费用是1w的,转移再100就爆了
    但是因为只要存个真假所以直接上bitset
    bitset大法好啊
     1 #include<set>
     2 #include<map>
     3 #include<cmath>
     4 #include<ctime>
     5 #include<deque>
     6 #include<queue>
     7 #include<bitset>
     8 #include<cstdio>
     9 #include<cstdlib>
    10 #include<cstring>
    11 #include<iostream>
    12 #include<algorithm>
    13 #define LL long long
    14 #define inf 0x7fffffff
    15 #define pa pair<int,int>
    16 #define pi 3.1415926535897932384626433832795028841971
    17 using namespace std;
    18 inline LL read()
    19 {
    20     LL x=0,f=1;char ch=getchar();
    21     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    22     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    23     return x*f;
    24 }
    25 bitset <10005> f[110];
    26 bitset <10005> g[110];
    27 bool mrk[110][110];
    28 int ga[110][110];
    29 int gb[110][110];
    30 int n,m;
    31 int main()
    32 {
    33     n=read();m=read();
    34     for (int i=1;i<=m;i++)
    35     {
    36         int x=read(),y=read();
    37         mrk[x][y]=1;
    38         ga[x][y]=read();gb[x][y]=read();
    39     }
    40     f[1][0]=1;g[1][0]=1;
    41     for (int i=2;i<=n;i++)
    42         for (int j=1;j<i;j++)
    43         if (mrk[j][i])
    44         {
    45             int x=ga[j][i],y=gb[j][i];
    46             f[i]|=(f[j]<<x);
    47             g[i]|=(g[j]<<y);
    48         }
    49     for (int i=1;i<=10000;i++)
    50     {
    51         if (f[n][i]&&g[n][i])
    52         {
    53             printf("%d
    ",i);
    54             return 0;
    55         }
    56     }
    57     printf("IMPOSSIBLE
    ");
    58     return 0;
    59 }
    bzoj3890
    ——by zhber,转载请注明来源
  • 相关阅读:
    java web环境搭建
    java动手动脑异常处理
    java动手动脑多态
    python全栈开发day67--字段类型、字段属性、ORM回顾
    python全栈开发day66-视图系统、路由系统
    python全栈开发day65-templates:tags、母版和继承、组件、静态文件相关、simple_tag和inclusion_tag
    python全栈开发day64-模板-变量和(.)的使用,filters和自定义filter
    Django Models的数据类型汇总
    nginx反向代理uwsgi django服务器搭建总结
    Centos更新yum源
  • 原文地址:https://www.cnblogs.com/zhber/p/4845198.html
Copyright © 2011-2022 走看看