zoukankan      html  css  js  c++  java
  • 【hdu 6000】Wash

    【链接】 我是链接,点我呀:)
    【题意】

    在这里输入题意

    【题解】

    因为每件衣服都是没有区别的。 只有洗衣机不同会影响洗衣时间。 那么我们把每台洗衣机洗衣的时间一开始都加入到队列中。 比如{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;
    }
    
  • 相关阅读:
    P24—动态数组没有{}
    JavaB站学习————接口在开发中的作用
    JavaB站学习————extends和implements同时出现
    JavaB站学习————一个类可以实现多个接口以及接口的总结
    JavaB站学习————接口和多态联合使用。
    01日语五十音
    07 递归&&命名风格&&作业(结构体,malloc,函数,递归)
    JavaB站学习——作业16
    电子书
    破解压缩包
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7991753.html
Copyright © 2011-2022 走看看