NOIP2017模擬 鴨舌

2021-08-03 15:37:10 字數 2192 閱讀 8094

題目:

小美喜歡吃鴨舌。

有乙個 n 個點的樹,每個節點 i ,第 i 個點上有 ai

個鴨舌。

小美一開始處於 x 號點。

每次小美可以選擇乙個與現在的點有邊的點而且那個點還有鴨舌,那麼小美會走到那個點並吃乙個鴨舌。

要保證小美最後還是走到 x 號點。

問小美最多能吃幾個鴨舌?

輸入格式

輸入第一行乙個整數 n 。

接下來一行 n 個整數表示 ai

。 下面是 n-1 行每行兩個整數表示一條邊。

最後一行乙個整數表示 x 。

輸出格式

輸出一行,乙個整數,表示吃最多的鴨舌個數。

樣例資料 1

輸入 5

1 3 1 3 2

2 5

3 4

4 5

1 5

4 輸出

6樣例資料2

輸入 3

2 1 1

3 2

1 2

3 輸出

2備註

【資料規模】

對於 30% 的資料:n≤5;ai

≤5;

對於 100% 的資料:1≤n≤100000;0≤ai

≤109 ;1≤x≤n。

分析:剛開始想到應該dp,但是邏輯總是出錯,花出大把時間,最後時間不夠了想打暴力,也寫錯了……思路主要是對於乙個節點,找到它的所有兒子,每乙個兒子又有自己對應的子樹,就這樣深搜到底。

**:

30分暴搜(就是乙個老鼠走迷宮,我**能力太弱啦,居然打錯):

#include

#include

#include

#include

#include

#include

#include

#include

#include

using

namespace

std;

const

int n=100005;

long

long a[n];

int n,x;

int first[n],next[n*2],go[n*2],tot=0;

long

long ans=0;

inline

void comb(int a,int b)

inline

void dfs(int now,long

long tot)

a[now]++;

}int main()

scanf("%d",&x);

dfs(x,0);

cout

0;}

100分**:

#include

#include

#include

#include

#include

#include

#include

using

namespace

std;

int getint()

const

int n=2e5+5;

int n,tot,root,len,a[n],size[n];

int first[n],next[n],to[n];

long

long f[n],cnt[n],tmp[n];

void add(int x,int y)

bool cmp(const

long

long &a,const

long

long &b)

void dfs(int x,int fa)

}if(a[x]>=size[x])//如果a[x]>size[x],說明可以把每個子樹都走一遍

else

//如果父親的鴨舌量不夠走完所有子樹

}int main()

root=getint();

dfs(root,0);

cout

0;}

本題結。

NOIP2017模擬 區間

2017.11.3 t1 2032 樣例資料 輸入3 2 1 2 1 1 2 4 5輸出 2 6分析 這道題為什麼要放在t1 考得我懷疑人生。本來也只會暴力找,對於30 的資料我是這樣的 先離散化,再二維陣列記錄所有顏色的在每個位置的字首和,然後四層迴圈暴力查詢。而正解是 先離散化,再把每種顏色的每...

NOIP2017模擬 舉辦比賽

2017.8.27 t1 1946 樣例資料1 輸入5 5 1 2 3 4 5 輸出 樣例資料2 輸入10000000 10000000 555 888 777 666 12345 輸出 分析 第一次做這種隨機概率題 看到資料那麼大o n 的做法根本想不到就直接放棄了。結果就是個撞運氣的ffffff...

NOIP2017模擬 太空電梯

2017.8.29 t1 1952 樣例資料 輸入6 6 1 2 3 3 4 5 輸出 分析 基本上是用貪心,就是找正好一胖一瘦沒法一起進電梯的一前一後,如果瘦的無法滿足,就和另外乙個瘦子一起把電梯人數擠滿 注意最後只剩乙個人時也要搭一次電梯 include include include incl...