2020.1.11考试总结

恭贺 treAKer 在毒瘤之神的考验一题中rank1,成为新一届毒瘤之神!
......
结果今天就考了 treAKer 的毒瘤题...

T1
考场上看到1e6就想O(n)的做法,结果失败了...
正解思路很神奇,就是先对物品按照a来排序,询问按照m来排序,用双指针一起扫,同时维护\(f_i\) 当物品的和为i时 在所有的方案中,最小的b最大 的方案中的 b值。判一下\(f_i\)和m+s的大小关系即可。

#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstdio>
using namespace std;
int n, Q, now;
const int N = 1005;
int ans[1000010], f[100010];
struct wu
{
    int a, b, c;
    friend bool operator <(const wu &a, const wu &b){return a.a < b.a;}
} w[1005];
struct Ask
{
    int m, k, s, id;
    friend bool operator <(const Ask &a, const Ask &b){return a.m < b.m;}
} q[1000010];
inline int read()
{
    int res = 0; char ch = getchar(); bool XX = false;
    for (; !isdigit(ch); ch = getchar())(ch == '-') && (XX = true);
    for (; isdigit(ch); ch = getchar())res = (res << 3) + (res << 1) + (ch ^ 48);
    return XX ? -res : res;
}
int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)w[i].c = read(), w[i].a = read(), w[i].b = read();
    cin >> Q;
    for (int i = 1; i <= Q; ++i)q[i].m = read(), q[i].k = read(), q[i].s = read(), q[i].id = i;
    sort(w + 1, w + 1 + n); sort(q + 1, q + 1 + Q);
    now = 1; f[0] = 1 << 30;
    for (int i = 1; i <= Q; ++i)
    {
        while (w[now].a <= q[i].m && now <= n)
        {
            for (int k = 100000; k >= w[now].c; --k)
                f[k] = max(f[k], min(f[k - w[now].c], w[now].b));
            ++now;
        }
        ans[q[i].id] = (f[q[i].k] > q[i].m + q[i].s);
    }
    for (int i = 1; i <= Q; ++i)puts(ans[i] ? "TAK" : "NIE");
    return 0;
}

T2
\(O(n^2)\)的DP很好推,f[i]=min(f[j],max(h[j+1...i]))(\(sum[i]-sum[j] \le L\))
发现最大值在一定的区间内不会变,并且j越小,f值越小,单调栈优化DP一下...
停,怎么只有95分啊?原来这不是正解啊..会被j单调递减的数据卡成\(O(n^2)\)...
其实这时候看情况只要翻转一下序列就行了,又变成\(O(n)\)了...
但会被h一大一小的数据卡掉...,虽然没有这样的数据,但我还是要讲一下正解。
正解就是用线段树优化DP,同时维护f和max就可以了。
事实证明,暴力还是很重要的.
考场95分代码

#include<iostream>
#include<cstring>
#include<cstdio>
#include<ctime>
#define int long long
using namespace std;
int n, L, top, cnt;
const int N = 100010;
int h[N], w[N], s[N], f[N], l[N], zhan[N];
inline int read()
{
    int res = 0; char ch = getchar(); bool XX = false;
    for (; !isdigit(ch); ch = getchar())(ch == '-') && (XX = true);
    for (; isdigit(ch); ch = getchar())res = (res << 3) + (res << 1) + (ch ^ 48);
    return XX ? -res : res;
}
void solve1()
{
    int tmp, mx;
    memset(f, 0x3f, sizeof(f)); f[0] = 0;
    for (int i = 1; i <= n; ++i)
    {
        tmp = 0; mx = -1;
        for (int j = i; j >= 1; --j)
        {
            tmp += w[j]; mx = max(mx, h[j]);
            if (tmp > L)break;
            f[i] = min(f[i], f[j - 1] + mx);
        }
    }
    cout << f[n];
}
void solve2()
{
    for (int i = 1; i <= n; ++i)
    {
        while (top && h[zhan[top]] <= h[i])--top;
        l[i] = zhan[top]; zhan[++top] = i;
    }
    for (int i = 1; i <= n; ++i)s[i] = s[i - 1] + w[i];
    int tmp, mx, pos;
    memset(f, 0x3f, sizeof(f)); f[0] = 0;
    for (int i = 1; i <= n; ++i)
    {
        pos = i + 1;
        while (1)
        {
            mx = h[pos - 1]; pos = l[pos - 1] + 1; tmp = s[i] - s[pos - 1];
            if (tmp > L)pos = lower_bound(s + 1, s + 1 + n, s[i] - L) - s;
            while (s[i] - s[pos - 1] > L)pos++;
            f[i] = min(f[i], f[pos - 1] + mx);
            if (pos == 1 || tmp > L)break;
        }
    }
    cout << f[n];
}
int TT;
inline void Swap(int &x, int &y) {TT = x; x = y; y = TT;}
signed main()
{
    cin >> n >> L;
    h[0] = 1e15;
    for (int i = 1; i <= n; ++i)h[i] = read(), w[i] = read(), cnt += (h[i] < h[i - 1]);
    if (cnt > n / 2)
        for (int i = 1, to = n / 2; i <= to; ++i)Swap(h[i], h[n - i + 1]), Swap(w[i], w[n - i + 1]);
    if (n <= 5000)solve1();
    else solve2();
    fclose(stdin); fclose(stdout);
    return 0;
}

正解

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define int long long
#define lson (k<<1)
#define rson ((k<<1)|1)
using namespace std;
int n, L, top;
const int N = 100010, inf = 1e18;
int h[N], w[N], s[N], l[N], dp[N], zhan[N], sum[N];
int tr[N << 2], f[N << 2], tag[N << 2];
inline int read()
{
    int res = 0; char ch = getchar(); bool XX = false;
    for (; !isdigit(ch); ch = getchar())(ch == '-') && (XX = true);
    for (; isdigit(ch); ch = getchar())res = (res << 3) + (res << 1) + (ch ^ 48);
    return XX ? -res : res;
}
void upd(int k)
{
    f[k] = min(f[lson], f[rson]); tr[k] = min(tr[lson], tr[rson]);
}
void down(int k)
{
    if (tag[k] == inf)return;
    tr[lson] = f[lson] + tag[k]; tr[rson] = f[rson] + tag[k];
    tag[lson] = tag[rson] = tag[k];
    tag[k] = inf;
}
void build(int k, int l, int r)
{
    tr[k] = f[k] = tag[k] = inf;
    if (l == r)return;
    int mid = (l + r) >> 1;
    build(lson, l, mid); build(rson, mid + 1, r);
}
void Insert(int k, int l, int r, int pos)
{
    if (l == r)
    {
        f[k] = dp[pos - 1]; tr[k] = inf;
        return;
    }
    down(k);
    int mid = (l + r) >> 1;
    if (pos <= mid)Insert(lson, l, mid, pos);
    else Insert(rson, mid + 1, r, pos);
}
void change(int k, int l, int r, int x, int y, int val)
{
    if (x <= l && r <= y)
    {
        tr[k] = f[k] + val; tag[k] = val;
        return;
    }
    down(k);
    int mid = (l + r) >> 1;
    if (x <= mid)change(lson, l, mid, x, y, val);
    if (mid + 1 <= y)change(rson, mid + 1, r, x, y, val);
    upd(k);
}
int ask(int k, int l, int r, int x, int y)
{
    if (x <= l && r <= y)return tr[k];
    down(k);
    int mid = (l + r) >> 1, ans = inf;
    if (x <= mid)ans = min(ans, ask(lson, l, mid, x, y));
    if (mid + 1 <= y)ans = min(ans, ask(rson, mid + 1, r, x, y));
    return ans;
}
signed main()
{
    cin >> n >> L;
    for (int i = 1; i <= n; ++i)h[i] = read(), w[i] = read(), sum[i] = sum[i - 1] + w[i];
    for (int i = 1; i <= n; ++i)
    {
        while (top && h[zhan[top]] <= h[i])--top;
        l[i] = zhan[top]; zhan[++top] = i;
    }
    build(1, 1, n);
    for (int i = 1; i <= n; ++i)
    {
        Insert(1, 1, n, i);
        change(1, 1, n, l[i] + 1, i, h[i]);
        int pos = lower_bound(sum, sum + i + 1, sum[i] - L) - sum;
        if (pos < i)dp[i] = ask(1, 1, n, pos + 1, i);
    }
    cout << dp[n];
    fclose(stdin); fclose(stdout);
    return 0;
}

原文地址:https://www.cnblogs.com/wljss/p/12181360.html

时间: 2024-08-30 14:02:42

2020.1.11考试总结的相关文章

9.11考试总结

# 9.11考试总结 细胞分裂 数学题目,因式分解后直接判断输入数据是否含有m1中分解出来的数,然后储存需要时间最大值中的最小值 #include<bits/stdc++.h> #define open(s) freopen(s".in", "r", stdin);// freopen(s".out", "w", stdout); #define IL inline #define ull unsigned lon

10.11考试总结

10.11考试总结 全是DP实际上发现暴力也能有部分分....... 三角形牧场 DP......当时总是感觉不像啊 需要处理的就是枚举三角形边长可能出现的情况.因为周长在输入端时候就可以确定了,所以只需要通过枚举两条边就可以强行算出第三条边..... 所以就省空间+时间.... f[0][0] = 1; for (int i=1; i<=n; ++i) for(int j=half; j>=0; j--) for(int k=j; k>=0; k--) if(j >= d[i]

脱产备考CPA是孤注一掷?应该如何备考2020年注册会计师考试?

在浩浩荡荡的CPA备考大军中,有朝九晚五想要寻求职业突破的上班族,有家务孩子一把抓的全职妈妈,也有想要奋力一搏的脱产人员--背景不同,面临的问题当然有所不同.而与其他人相比,脱产备考的考生心理压力总是格外的重,毕竟没有工作,没有收入,甚至可能得不到家人朋友的理解,如此全力以赴.孤注一掷的冒险,无非是希望自己能比别人多占据一些备考优势,那么脱产人员应该如何备考2020年注册会计师考试呢?老实说,对于选择脱产备考的人来说,时间确实足够充裕,但要想把时间充分利用起来,争取一次性过五科甚至六科,以下几个

Daily Recording 2020/01/11 (关键词:ARP,计算机网络基础)

Daily Recording Wang yuan can January 11, 2020 @雨人网安 日报 日报开始 今天是周六,持续六天的高强度学习迎来了“伟大的休息日”,今天的学习内容相对轻松,刚开始Bai在讲计算机网络基础的时候希望通过小视频的方式让我们来了解,后面越看越跑题了,原子弹制造.高铁运作流程.飞机票出票流程......,就这样,我们在bilibili看一上午有趣的小视频.下午Bai带着我们阅读了一个关于“内网渗透”的博文,讲的是博主如何渗透进蹭自己家wifi的人的电脑,后面

6.11 考试修改+总结

第三题至今没敢写,感觉好恐怖QAQ 今天考得好糟糕 第一题只写了10分的暴力+(k=1)20分的网络流 后来题解告诉我k>1的时候可以分治到k=1,每层分治解决方法是同k=1的 考试的时候没有注意到2^k这个比较神奇的可以分治的性质 而且自己考场上丝薄了,没有发现因为是二分图可以直接跑欧拉回路的性质,而是裸套网络流模型 第二题其实已经接近想出了题解 自己考试的时候成功证明了暴力的复杂度是线性的 但是没有想到如何寻找0-1对,然后就只能暴力用Splay维护1所在的位置了 默默祈祷数据不要太卡我的做

2020.1.9考试总结

T1 数据范围很合适.. 第一档就是暴力枚举 第二档就是数位DP 第三档就是矩阵乘法 丢一下学长的博客 #include<iostream> #include<cstring> #include<cstdio> #define LL long long using namespace std; LL n; const int mod = 1e9 + 7; struct ju { LL c[4][4]; friend ju operator *(const ju &

[题解] 8.11考试 水渠

题目描述 把n+m个点分为两列,第一列有n个点,第二列有m个点. 每一列的点的横坐标相同,给这些点连边,将这n+m个点全部连通,求所连边的最小总和. 输入格式 第一行四个整数n,m,x1,x2,分别表示第一列的点数,第二列的点数,第一列中点的横坐标,第二列中的点的横坐标. 第二行n个正整数y1[1],y1[2],...,y1[n],表示第一列中的点的纵坐标. 其中,第一个数表示第一个点的纵坐标,接下来的数表示当前点与前一个点的纵坐标差. 第三行有m个正整数,意义同上. 输出格式 一个实数,为边的

2020.1.2考试总结

T1圆圈游戏 暴力DP有60分,设包含圆i的最小的圆是fa[i],那没最终会的得到一棵树,对于一棵子树,选了根节点就不能选子树内其它点,f[i]=max(w[i],\(\sum f[son]\)). 瓶颈就在怎么建图,因为圆不相交相切,所以扫描线的时候相对位置不会发生改变,用set维护一下就好啦. #include<algorithm> #include<iostream> #include<cmath> #include<queue> #include&l

Expired in March 11, 2020(2020.3.11 到期)

CATF44LT7C-eyJsaWNlbnNlSWQiOiJDQVRGNDRMVDdDIiwibGljZW5zZWVOYW1lIjoiVmxhZGlzbGF2IEtvdmFsZW5rbyIsImFzc2lnbmVlTmFtZSI6IiIsImFzc2lnbmVlRW1haWwiOiIiLCJsaWNlbnNlUmVzdHJpY3Rpb24iOiJGb3IgZWR1Y2F0aW9uYWwgdXNlIG9ubHkiLCJjaGVja0NvbmN1cnJlbnRVc2UiOmZhbHNlLCJwcm9