麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

Hrbust 2292 Tom and Jerry【樹上最短路+枚舉】

2019-11-11 01:59:16
字體:
來源:轉載
供稿:網友

Tom and Jerry
Time Limit: 3000 MSMemory Limit: 327680 K
Total Submit: 68(18 users)Total Accepted: 20(16 users)Rating: Special Judge: No
Description

Tom and Jerry are trapped in a tree with n vertex (2 <= n <= 100000). Initially they are on two different vertex, as we know, jerry will run to his home and tom want to catch jerry before he reach his home. But unluckily, there are no home in this tree, so jerry’s being caught is just a matter of time. Your task is to calculate the minimal time tom can catch jerry (Tom catch Jerry means they are at the some vertex at the same time). To make things simple, we define that every second, Jerry make his choice first and then Tom make his choice. Of course, both of them will choose their way optimally. 

We define every move as follow:

At every move, Tom or Jerry can choose whether to move to an adjacent vertex or just stay where he is. 

We define the speed as follows:

Speed v means Tom or Jerry can make at most v moves in every second.

You should know that Jerry's speed is always 1, Tom's speed is v.

Input

The first line contains an integer T, then T cases follows. 

In each case, there are n+1 lines of input. The first line is a single integer n, indicating the number of vertex numbered from 0 to n-1. Each of the next n-1 lines contains 2 integers a and b, means there is an edge between a and b.

The last line contains 3 integers t, j and v(v < min(n, 20)), means the initial place of Tom and Jerry and Tom's speed.

Output
For each case, you should output the minimal time Tom needed to catch Jerry.
Sample Input
290 11 22 33 44 52 66 77 85 0 190 11 22 33 44 52 66 77 80 5 1
Sample Output
65
Source
"尚學堂杯"哈爾濱理工大學第五屆程序設計團隊賽(正式)

題目大意:

現在有N個點的一棵樹,初始的時候貓和老鼠的位子已知,老鼠的速度永遠都是1,貓的速度是V.

對于速度,表示一秒可以進行的操作次數,每一秒都可以進行兩種操作:移動到相鄰的點,或者是不動。

問最慢貓抓到耗子的時間。

思路:

1、肯定耗子想要跑的盡可能的遠,而且在跑到那個終點位子End之前的路徑上,貓不會抓到耗子。

那么我們可以通過枚舉End這個點來判斷,對于一個點u,如果耗子到達這個點的耗用時間量小于貓到達這個點的耗用時間量,那么這個點就可以作為End點。而且在這個點u貓抓到耗子的時間就是貓到達這個點的時間。

過程維護最大,那么滿足條件的最大時間,就是最終答案。

2、因為題目要求耗子和貓都會做出最優的決策,那么肯定是要處理兩次樹上的最短路,處理出來貓和耗子到各個點的最短路徑長度,然后計算時間維護滿足條件的最大時間即可。

Ac代碼:

#include<stdio.h>#include<string.h>#include<vector>using namespace std;vector<int >mp[100600];int vis[100600];int dis[2][100600];void Dfs(int u,int d){    vis[u]=1;    for(int i=0;i<mp[u].size();i++)    {        int v=mp[u][i];        if(vis[v]==0)        {            vis[v]=1;            dis[d][v]=dis[d][u]+1;            Dfs(v,d);        }    }}int main(){    int t;    scanf("%d",&t);    while(t--)    {        int n;        scanf("%d",&n);        memset(dis,0,sizeof(dis));        for(int i=1;i<=n;i++)mp[i].clear();        for(int i=0;i<n-1;i++)        {            int x,y;            scanf("%d%d",&x,&y);            mp[x].push_back(y);            mp[y].push_back(x);        }        int t,j,v;        scanf("%d%d%d",&t,&j,&v);        memset(vis,0,sizeof(vis));        Dfs(t,0);        memset(vis,0,sizeof(vis));        Dfs(j,1);        int ans=0;        for(int i=1;i<=n;i++)        {            int tmp=dis[0][i]/v;            if(dis[0][i]%v!=0)tmp++;            if(tmp>dis[1][i])            {                ans=max(ans,tmp);            }        }        PRintf("%d/n",ans);    }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 日本成人在线播放 | 黄色特级片黄色特级片 | 九九热精彩视频 | 久久久精品视频在线观看 | 男女无遮挡羞羞视频 | 大片毛片 | 经典三级在线视频 | 成年人网站视频免费 | 成人三级电影网址 | 国产精品久久久久久久久久久久久久久 | 天天艹综合 | 亚洲国产精品久久久久婷婷老年 | 毛片免费一区二区三区 | 欧美日韩精品不卡一区二区三区 | 久久久久免费精品 | 成人免费av在线 | 国产亚洲精品一区二区三区 | 成年免费视频黄网站在线观看 | 91av在线影院| 亚洲aⅴ在线观看 | 国产91一区二区三区 | 日韩一级精品 | 成人啪啪18免费网站 | 国产精品自拍片 | 成人在线视频播放 | 成av在线 | 亚洲国产二区 | 欧美日韩亚洲一区二区三区 | 久久精品99国产国产精 | 久久久成人一区二区免费影院 | 粉嫩av一区二区三区四区在线观看 | 欧美日韩精品中文字幕 | 国产在线观看免费视频软件 | 最近国产中文字幕 | 欧美日韩视频在线播放 | 少妇一级淫片免费看 | 亚洲午夜精品视频 | 成人毛片网站 | 成人三级免费电影 | 999精品久久久| 国产精品探花在线观看 |