1. 程式人生 > >【hdu 6000】Wash

【hdu 6000】Wash

long -- 含義 影響 cnblogs 再次 require sample 隊列

【鏈接】 我是鏈接,點我呀:)
【題意】


在這裏輸入題意

【題解】


因為每件衣服都是沒有區別的。
只有洗衣機不同會影響洗衣時間。
那麽我們把每臺洗衣機洗衣的時間一開始都加入到隊列中。
比如{2,3,6,7}
這個隊列裏面的數字就代表了如果某件衣服用這臺洗衣機洗的話,要在什麽時刻洗好。
對於每一件衣服i。
取出隊列的頭。
這裏為2
那麽就a[i] = 2,表示第i件衣服最早在a[i] = 2時刻洗好
然後再把2+t[i]加入到隊列中即{3,2+t[i],6,7} (這裏t[i]即等於2)
每次都取出隊頭即可。

然後是烘幹的過程。
貪心的方法是,最晚洗好的那一件衣服
(這裏因為我們第一步貪心的時候,是順序枚舉每一件衣服的,所以最晚洗好的那一件衣服一定是a[L])

一定要用最快的烘幹機去烘幹它。
按照這個去貪心就好。

這個過程其實不是很好理解
代碼中 取出最快的烘幹機之後,把{temp.first+temp.second,temp.second}再次加入到隊列中,實際含義
其實就是說,如果有另外一件衣服還要用這臺機器烘幹的話,那麽得多出來temp.second的時間,讓給前面
的衣服->但是也可能不用讓,不用讓也沒事,那麽之前得到的一定是更大的值.
這點是需要動腦子的地方。

【代碼】

/*
    1.Shoud it use long long ?
    2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal 4.use the puts("") or putchar() or printf and such things? 5.init the used array or any value? 6.use error MAX_VALUE? 7.use scanf instead of cin/cout? 8.whatch out the detail input require */ #include <bits/stdc++.h>
#define ll long long using namespace std; const int N = 1e6+10; ll a[N]; int T,l,n,m; priority_queue <pair<ll,ll> ,vector <pair<ll,ll> >,greater <pair<ll,ll> > > q; int main(){ #ifdef LOCAL_DEFINE freopen("F:\\c++source\\rush_in.txt", "r", stdin); #endif int kase = 0; ios::sync_with_stdio(0),cin.tie(0); cin >> T; while (T--){ cin >> l >> n >> m; for (int i = 1;i <= n;i++){ ll x; cin >> x; q.push({x,x}); } for (int i = 1;i <= l;i++){ a[i] = q.top().first; pair<ll,ll> temp = q.top(); q.pop(); temp.first += temp.second; q.push(temp); } while (!q.empty()) q.pop(); for (int i = 1;i <= m;i++){ ll x; cin >> x; q.push(make_pair(x,x)); } ll ma = 0; for (int i = l;i >= 1;i--){ pair <ll,ll> temp = q.top(); q.pop(); ma = max(ma,a[i]+temp.first); temp.first+=temp.second; q.push(temp); } while (!q.empty()) q.pop(); cout << "Case #"<<++kase<<": "<<ma<<endl; } return 0; }

【hdu 6000】Wash