PAT_A 1003. Emergency (25)

1003. Emergency (25)

As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair of cities are marked on the map. When there is an emergency call to you from some other city, your job is to lead your men to the place as quickly as possible, and at the mean time, call up as many hands on the way as possible.

Input

Each input file contains one test case. For each test case, the first line contains 4 positive integers: N (<= 500) - the number of cities (and the cities are numbered from 0 to N-1), M - the number of roads, C1 and C2 - the cities that you are currently in and that you must save, respectively. The next line contains N integers, where the i-th integer is the number of rescue teams in the i-th city. Then M lines follow, each describes a road with three integers c1, c2 and L, which are the pair of cities connected by a road and the length of that road, respectively. It is guaranteed that there exists at least one path from C1 to C2.

Output

For each test case, print in one line two numbers: the number of different shortest paths between C1 and C2, and the maximum amount of rescue teams you can possibly gather.
All the numbers in a line must be separated by exactly one space, and there is no extra space allowed at the end of a line.
Sample Input

5 6 0 2
1 2 1 5 3
0 1 1
0 2 2
0 3 1
1 2 1
2 4 1
3 4 1

Sample Output

2 4

  • 分析
    • 最开始做pat时,那时的感觉是,哇,太难了!不过经过将近30道题的练习,现在这道题目时,是多么的简单。算法的确很难,但经过学习和练习之后,能够看到自己的进步就很开心!来说这道题,就是一个简单的图,求最短路径,只用dfs就能解决,dijkstra都没用上。
    • 自己做时,对题目的理解有点问题(被1111那道题整恶心了)
      • 所求最大队伍数:最短路径的那几条路中大的队伍数
      • 这里的路是双向的即,p[x][y]=p[y][x]
  • code
#include<iostream>
#include<vector>
using namespace std;
int path[510][510];
int hands[510];
bool visit[510];
int N,M,C1,C2;
int _min=-1;
int count=0;
int _max=-1;
void dfs(int a,int b,int len,int han)
{
    if(a==b)
    {
        if(_min==-1)
        {
          _min=len;
          count=1;
          _max=han;
        }
        else if(_min>len)
        {
            count=1;
            _min=len;
            _max=han;
        }else if(_min==len)
        {
            //题目没说是在最短路中寻找最大人数
            //但想想也是啊
            count++;
            if(han>_max)
              _max=han;
        }
        return ;
    }
    visit[a]=true;
    for(int i=0;i<N;i++)
    {
        if(path[a][i]!=-1&&visit[i]==false)
        dfs(i,b,len+path[a][i],han+hands[i]);
    }
    visit[a]=false;
}
int main()
{
    for(int i=0;i<510;i++)
    {
        visit[i]=false;
        for(int j=0;j<510;j++)
          path[i][j]=-1;
    }
    cin>>N>>M>>C1>>C2;
    for(int i=0;i<N;i++)
    {
        cin>>hands[i];
    }

    int x,y;
    for(int i=0;i<M;i++)
    {
        cin>>x>>y;
        //没说单向路还是双向,那就是双向
        cin>>path[x][y];
        path[y][x]=path[x][y];
    }
    dfs(C1,C2,0,hands[C1]);
    cout<<count<<" "<<_max<<endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
select distinct a.EMPI_ID, a.PATIENT_NO, a.MR_NO, a.PAT_NAME, a.PAT_SEX, a.PAT_AGE, a.PAT_PHONE_NO, b.DIAG_RESULT, a.ADMIT_DATE, a.DISCHARGE_DEPT_NAME, a.ATTEND_DR from BASIC_INFORMATION a join PA_DIAG b on a.MZZY_SERIES_NO=b.MZZY_SERIES_NO join EXAM_DESC_RESULT_CODE c on a.MZZY_SERIES_NO=c.MZZY_SERIES_NO join DRUG_INFO d on a.MZZY_SERIES_NO=d.MZZY_SERIES_NO join EMR_CONTENT e on a.MZZY_SERIES_NO=e.MZZY_SERIES_NO JOIN TEST_INFO A17 ON a.MZZY_SERIES_NO = A17.MZZY_SERIES_NO where a.PAT_AGE>='18' and (to_char(a.ADMIT_DATE,'YYYY-MM-DD') >= '2021-01-01') AND (b.DIAG_RESULT LIKE '%鼻咽癌%' or b.DIAG_RESULT LIKE '%鼻咽恶性肿瘤%' or b.DIAG_CODE LIKE '%C11/900%') and d.DRUG_NAME not in (select DRUG_NAME FROM DRUG_INFO WHERE DRUG_NAME like '卡培他滨') and b.DIAG_RESULT NOT IN (SELECT DIAG_RESULT FROM PA_DIAG WHERE DIAG_RESULT LIKE '%HIV阳性%') and b.DIAG_RESULT NOT IN (SELECT DIAG_RESULT FROM PA_DIAG WHERE DIAG_RESULT LIKE '%充血性心力衰竭%') AND to_char(( A17.TEST_DETAIL_ITEM_NAME = '中性粒细胞' AND A17.TEST_RESULT >= 1.5 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '血小板' AND A17.TEST_RESULT >= 100 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '血红蛋白' AND A17.TEST_RESULT >= 9 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '丙氨酸氨基转移酶' AND A17.TEST_RESULT <= 2.5 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '天门冬氨酸氨基转移酶' AND A17.TEST_RESULT <= 2.5 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '肌酐清除率' AND A17.TEST_RESULT > 51 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '肌酐' AND A17.TEST_RESULT <=1.5 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '凝血酶原时间' AND A17.TEST_RESULT <= 1.5 ))语句哪里有问题
06-07

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值