HDU 6698 Coins(貪心 線段樹)

2021-09-27 01:54:28 字數 2258 閱讀 3675

題意:現在有n

nn組數字,每組數字裡面有兩個數a

aa,b

bb,你需要從這n組數中取k(1

<=k

<=2

∗n

)k(1<=k<=2*n)

k(1<=k

<=2

∗n)個數,如果你要從一組數中取數,你只有三種取法

解題心得:

#include

using namespace std;

typedef

long

long ll;

const ll maxn =

1e6+

100;

const ll inf =

1e18

;struct node2 p[maxn]

;struct nodenode[maxn]

;ll n, t, ans[maxn]

;void

update

(ll root)

void

build_tree

(ll root, ll l,ll r)

ll mid = l + r >>1;

build_tree

(root<<

1, l, mid)

;build_tree

(root<<1|

1, mid+

1, r)

;update

(root);}

void

init()

build_tree(1

,1, n);}

void

changemaxa

(ll root, ll l, ll r, ll va)

ll mid = l + r >>1;

ll chl = root<<

1, chr = root<<1|

1;if(node[chl]

.maxa == node[root]

.maxa)

else

update

(root);}

void

changemaxb

(ll root, ll l, ll r, ll va)

ll mid = l + r >>1;

ll chl = root<<

1, chr = root<<1|

1;if(node[chl]

.maxb == node[root]

.maxb)

else

update

(root);}

void

changemina

(ll root, ll l, ll r, ll va)

ll chl = root<<

1, chr = root<<1|

1;ll mid = l + r >>1;

if(node[chl]

.mina == node[root]

.mina)

else

update

(root);}

void

changeminb

(ll root, ll l, ll r,ll va)

ll mid = l + r >>1;

ll chl = root<<

1, chr = root<<1|

1;if(node[chl]

.minb == node[root]

.minb)

else

update

(root);}

void

changemaxab

(ll root, ll l, ll r)

ll mid = l + r >>1;

ll chl = root<<

1, chr = root<<1|

1;if(node[chl]

.maxab == node[root]

.maxab)

else

update

(root);}

void

solve()

else

}else

else

changemaxab(1

,1, n);}

sum =

max(sum1, sum2)

; ans[i]

= sum;}}

intmain()

}return0;

}

HDU 2844 Coins 多重揹包

include include include include include using namespace std define clr c,v memset c,v,sizeof c const int inf 1 30 const int inf 1 30 const int m 1e5 1...

HDU 2844 Coins(多重揹包)

以前做題目光僅僅侷限於 0 1 揹包 和 完全揹包了。出來乙個 個數確定的揹包就不會了。看了網上的題解。原來是多重揹包。也就是說 用完全揹包和 0 1揹包混合求解的題目。應該是。對於 vi a i m 那麼就相當於乙個完全揹包。因為數量可以超過 最大限制。那麼就可以當做無限個使用。其他的 就需要二進...

hdu 2844 Coins 多重揹包

題意 給你一些不同價值和一定數量的硬幣,求用這些硬幣可以組合成價值在 1 m 之間的有多少 dp i 來表示容量為i這個包包可以裝多少價值,最後計數是要計價值和容量相等的個數 include include includeusing namespace std int sum,dp 100010 v...