Link

current : 5 / 9

 A. The beautiful values of the palace????

 B. super_log????

 C. Tsy's number 5

 D. Robots

  概率DP

 E. K Sum

 F. Greedy Sequence????

 G. Quadrilateral

  

 H. Holy Grail????

 

https://blog.csdn.net/TDD_Master/article/details/100374149

学习了贪心的一个写法。

我们先把洗衣顺序按时间排序。

最后的策略一定是,前 $j$ 个人手洗,之后的人用洗衣机洗。

我们枚举x 在$[1, y]$的值,每次只有后 y/x个人可能用洗衣机洗。

复杂度是一个调和级数。

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize(4)
#include <algorithm>
#include  <iterator>
#include  <iostream>
#include   <cstring>
#include   <cstdlib>
#include   <iomanip>
#include    <bitset>
#include    <cctype>
#include    <cstdio>
#include    <string>
#include    <vector>
#include     <stack>
#include     <cmath>
#include     <queue>
#include      <list>
#include       <map>
#include       <set>
#include   <cassert>
#include <unordered_set>
// #include<bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9+7;

template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}

/**********showtime************/

            const int maxn = 1e6+9;
            int t[maxn];
int main(){
            int n,m;
            while(~scanf("%d%d", &n, &m)) {
                for(int i=1; i<=n; i++) scanf("%d", &t[i]);
                sort(t+1, t+1+n);
                for(int i=1; i<=m; i++) {
                    int x = i, y = m;
                    int cnt = min(n, y / x);
                    ll ans = inff;
                    ll bk = 0;
                    for(int j=n; j>=(n - cnt + 1); j--) {
                        ll t1 = 1ll * (n-j+1)*x + t[j];
                        bk = max(bk, t1);
                        t1 = bk;
                        if(j > 1) t1 = max(t1, 1ll*t[j-1] + y);
                        ans = min(ans, t1);
                    }
                    if(i < m) printf("%lld ", ans);
                    else printf("%lld\n", ans);
                }
            }
            return 0;
}
View Code

相关文章:

  • 2022-12-23
  • 2021-04-22
  • 2021-12-04
  • 2021-12-21
  • 2021-12-04
  • 2021-12-04
  • 2019-09-01
  • 2022-01-23
猜你喜欢
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
  • 2021-06-23
  • 2022-12-23
相关资源
相似解决方案