2019南京网络赛

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👌

 I. Washing clothes

 

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

 李超树

https://www.cnblogs.com/pkgunboat/p/11449031.html

// #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;
            ll a[maxn];
            ll ans[maxn];
            struct node{
                int flag;
                int k, b;
                ll cal(int x) {
                    return 1ll*k * x + b;
                }
            }tree[maxn << 2];
            void build(int le, int ri ,int rt) {
                tree[rt].flag = 0;
                if(le == ri) return ;
                int mid = (le + ri) >> 1;
                build(le, mid, rt<<1);
                build(mid+1, ri, rt<<1|1);
            }
            void update(int k, int b, int le, int ri, int rt) {
                if(tree[rt].flag == 0) {
                    tree[rt].flag = 1;
                    tree[rt].k = k;
                    tree[rt].b = b;
                    return;
                }
                ll l1 = tree[rt].cal(le);
                ll r1 = tree[rt].cal(ri);
                ll l2 = 1ll*k * le + b;
                ll r2 = 1ll*k * ri + b;
                if(l1 >= l2 && r1 >= r2)  return;
                if(l1 <= l2 && r1 <= r2) {
                    tree[rt].k = k;
                    tree[rt].b = b;
                    return;
                }
                double pos = 1.0 * (b - tree[rt].b) / (tree[rt].k - k);
                int mid = (le + ri) >> 1;
                if(l1 >= l2) {
                    if(pos <= mid) {
                        update(tree[rt].k, tree[rt].b, le, mid, rt<<1);
                        tree[rt].k = k;
                        tree[rt].b = b;
                    }
                    else {
                        update(k, b, mid+1, ri, rt<<1|1);
                    }
                }
                else {
                    if(pos <= mid) {
                        update(k, b, le, mid, rt<<1);
                    }
                    else {
                        update(tree[rt].k, tree[rt].b, mid+1, ri, rt<<1|1);
                        tree[rt].k = k;
                        tree[rt].b = b;
                    }
                }
            }

            ll query(int pos, int le, int ri, int rt) {
                if(tree[rt].flag == 0) return 0;
                ll res = tree[rt].cal(pos);
                if(le == ri) return res;
                int mid = (le + ri) >> 1;
                if(pos <= mid) res = max(res,query(pos, le, mid, rt<<1));
                else res = max(res, query(pos, mid+1, ri, rt<<1|1));
                return res;
            }

int main(){
            int n,m;
            while(~scanf("%d%d", &n, &m)) {
                for(int i=1; i<=n; i++) scanf("%lld", &a[i]);
                sort(a+1, a+1+n);
                build(1, m, 1);
                update(1, a[n], 1, m, 1);
                a[0] = -m;
                int p = n-1;

                for(int x=m; x>=1; x--){
                    ll res = max(a[p] + m, query(x, 1, m, 1));
//                    cout<<x<<" , " << res<<endl;
                    while(p >= 1) {
                        int tmp = max(a[p-1] + m, max(a[p] + x * (n - p + 1), query(x, 1, m, 1)));
                        if(tmp <= res) {
                            res = tmp;
                            update(n - p + 1, a[p], 1, m, 1);
                            p--;
                        }
                        else break;
                    }
                    ans[x] = res;
                }

                for(int i=1; i<m; i++) printf("%lld ", ans[i]);
                printf("%lld\n", ans[m]);
            }
            return 0;
}
View Code

 

posted @ 2019-09-01 19:14  ckxkexing  阅读(248)  评论(0编辑  收藏  举报