zoukankan      html  css  js  c++  java
  • UVA

    题目描述

    输入输出格式

    输入格式:

    输出格式:

    输入输出样例

    输入样例#1: 
    2
    2 3 4 2
    96 97 199 62
    输出样例#1: 
    2 2
    9859 62
     1 #include<iostream>
     2 #include<cstdlib>
     3 #include<queue>
     4 #include<string>
     5 #include<algorithm>
     6 #include<cstdio>
     7 #include<cstring>
     8 using namespace std;
     9 const int maxn=200+5;
    10 struct node{
    11     int v[3];
    12     int dist;
    13     bool operator < (const node & rhs) const {
    14         return dist>rhs.dist;
    15     }
    16 };
    17 
    18 int vis[maxn][maxn];
    19 int cap[3],ans[maxn];
    20 
    21 inline void update_ans(const node & u)
    22 {
    23     for(int i=0;i<3;i++)
    24     {
    25         int d=u.v[i];
    26         if(ans[d]<0||u.dist<ans[d])
    27             ans[d]=u.dist;
    28     }
    29 }
    30 
    31 inline void solve(int a,int b,int c,int d)
    32 {
    33     cap[0]=a;
    34     cap[1]=b;
    35     cap[2]=c;
    36     memset(vis,0,sizeof(vis));
    37     memset(ans,-1,sizeof(ans));
    38     priority_queue<node>q;
    39     node start;
    40     start.dist=0;
    41     start.v[0]=0;
    42     start.v[1]=0;
    43     start.v[2]=c;
    44     q.push(start);
    45     vis[0][0]=1;
    46     while(!q.empty())
    47     {
    48         node u=q.top();
    49         q.pop();
    50         update_ans(u);
    51         if(ans[d]>=0)
    52             break;
    53         for(int i=0;i<3;i++)
    54         {
    55             for(int j=0;j<3;j++)
    56             {
    57                 if(i!=j)
    58                 {
    59                     if(u.v[i]==0||u.v[j]==cap[j])
    60                         continue;
    61                     int amout=min(cap[j],u.v[i]+u.v[j])-u.v[j];
    62                     node u2;
    63                     memcpy(&u2,&u,sizeof(u));
    64                     u2.dist=u.dist+amout;
    65                     u2.v[i]-=amout;
    66                     u2.v[j]+=amout;
    67                     if(!vis[u2.v[0]][u2.v[1]])
    68                     {
    69                         vis[u2.v[0]][u2.v[1]]=true;
    70                         q.push(u2);
    71                     }
    72                 }
    73             }
    74         }
    75     }
    76     while(d>=0)
    77     {
    78         if(ans[d]>=0)
    79         {
    80             printf("%d %d
    ",ans[d],d);
    81             return ;
    82         }
    83         d--;
    84     }
    85 }
    86 
    87 int main()
    88 {
    89     int t,a,b,c,d;
    90     scanf("%d",&t);
    91     while(t--)
    92     {
    93         scanf("%d%d%d%d",&a,&b,&c,&d);
    94         solve(a,b,c,d);
    95     }
    96     return 0;
    97 }
  • 相关阅读:
    【Android】Android如何实现手机震动
    【Android】详解Android的menu菜单
    【Smali】Smali文件的动态调试
    【C#】C#项目如何获得项目的根目录
    【Android】Android如何对APK签名
    【Android】Android如何对APK反编译
    【SqlServer】在SqlServer中把数据导入导出为Excel文件
    【C#】解析C#中JSON.NET的使用
    【C#】浅析C#中的日期处理
    TCP与UDP传输协议
  • 原文地址:https://www.cnblogs.com/Hammer-cwz-77/p/8511593.html
Copyright © 2011-2022 走看看