zoukankan      html  css  js  c++  java
  • Drying POJ

    题意:有N件湿的衣服,一台烘干机。每件衣服有一个湿度值。每秒会减一,如果用烘干机,每秒会减k。问最少多久可以晒完。

    题解:二分。首先时间越长越容易晒完。

        其次判定函数可以这样给出:对于答案 X,每一个湿度大于X的衣服都要被烘干。所以可以直接统计烘干机被用的总时间,如果其大于X则返回0.

        注意向下取整细节。

    #define _CRT_SECURE_NO_WARNINGS
    #include<cstring>
    #include<cctype>
    #include<cstdlib>
    #include<cmath>
    #include<cstdio>
    #include<string>
    #include<stack>
    #include<ctime>
    #include<list>
    #include<set>
    #include<map>
    #include<queue>
    #include<vector>
    #include<sstream>
    #include<iostream>
    #include<functional>
    #include<algorithm>
    #include<memory.h>
    //#define INF 0x3f3f3f3f
    #define eps 1e-6
    #define pi acos(-1.0)
    #define e exp(1.0)
    #define rep(i,t,n)  for(int i =(t);i<=(n);++i)
    #define per(i,n,t)  for(int i =(n);i>=(t);--i)
    #define mp make_pair
    #define pb push_back
    #define mmm(a,b) memset(a,b,sizeof(a))
    //std::ios::sync_with_stdio(false);
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    void smain();
    #define ONLINE_JUDGE
    int main() {
        ios::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        long _begin_time = clock();
    #endif
        smain();
    #ifndef ONLINE_JUDGE
        long _end_time = clock();
        printf("time = %ld ms.", _end_time - _begin_time);
    #endif
        return 0;
    }
    const int maxn = 1e5 + 5;
    int a[maxn];
    int n, k;
    int l, r, mid;
    bool check(int x) {
        int now = 0;//time for radiator
        rep(i, 1, n) {
            if (a[i] > x) {
                now += (a[i] - x - 1) / (k - 1) + 1;//k-1&&ceiling/consider integer 
                if (now > x)return 0;
            }
    
        }
        return 1;
    }
    void Run() {
        l = 0, r = 0;
        r = *max_element(a + 1, a + 1 + n);
        if (k == 1) { cout << r<<endl; }
        else {
            while (l <= r) {
                mid = l + r >>1;
                if (check(mid))r = mid - 1;
                else  l = mid + 1;
    
            }
            cout << l << endl;
        }
    }
    
    void smain() {
    
    
        cin >> n;
        rep(i, 1, n)cin >> a[i];
        cin >> k;
    
        Run();
        
    }
    成功的路并不拥挤,因为大部分人都在颓(笑)
  • 相关阅读:
    绘制程序流程图笔记
    强软弱虚引用
    安全点和安全区域
    垃圾回收算法
    垃圾回收相关算法
    内存访问全过程
    多级页表与快表
    分页
    虚拟内存
    内存分段机制
  • 原文地址:https://www.cnblogs.com/SuuT/p/8987588.html
Copyright © 2011-2022 走看看