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<cstdio>
#include<set>
using namespace std;
int n, ans, tmp, lx;
const int N = 200010;
int f[N], fa[N];
struct yuan
{
    int x, y, r, w;
    double h(int dir) {return y + dir * sqrt(1.0 * r * r - (1.0 * lx - x) * (lx - x));}
} y[N];
struct hu
{
    int dir, id;
    friend bool operator <(const hu &a, const hu &b)
    {return a.id == b.id ? a.dir < b.dir : (y[a.id].h(a.dir) < y[b.id].h(b.dir));}
} b[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;
}
int my(hu a, hu b) {return y[a.id].x - a.dir * y[a.id].r < y[b.id].x - a.dir * y[b.id].r;}
set<hu>s;
set<hu>::iterator it;
signed main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        y[i].x = read(); y[i].y = read(); y[i].r = read(); y[i].w = read();
        b[++tmp] = (hu) {1, i}, b[++tmp] = (hu) { -1, i};
    }
    sort(b + 1, b + 1 + tmp, my);
    for (int i = 1; i <= tmp; ++i)
    {
        int id = b[i].id, dir = b[i].dir;
        lx = y[id].x - dir * y[id].r;
        if (dir == 1)
        {
            if (!s.empty())
            {
                it = s.upper_bound(b[i]);
                if (it != s.end())
                    fa[id] = (it->dir == 1) ? it->id : fa[it->id];
            }
            s.insert((hu) {1, id}); s.insert((hu) { -1, id});
        } else
        {
            s.erase((hu) {1, id}); s.erase((hu) { -1, id});
            f[fa[id]] += max(f[id], y[id].w);
        }
    }
    cout << f[0];
    return 0;
}

T2划分序列
很明显的二分答案,关键就在于check。
设f1[i]表示在i处划分一下,在满足mid的条件下最少划分次数,f2[i]表示最多的划分次数,若\(f1[n] \le k \le f2[n]\)则mid合法。
暴力dp是\(O(n^2)\)的,发现更新f1,f2的是区间最大/最小值,用树状数组维护一下就可以了。

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
int n, k, ans, tot;
const int N = 100010, inf = 1 << 30;
int a[N], f1[N], f2[N], tr1[N], tr2[N], b[N], t1[N], t2[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;
}
inline int lowbit(int x) {return x & (-x);}
void change1(int pos, int val)
{
    for (; pos; pos -= lowbit(pos))tr1[pos] = min(tr1[pos], val);
}
int ask1(int pos)
{
    int res = inf;
    for (; pos <= tot; pos += lowbit(pos))res = min(res, tr1[pos]);
    return res;
}
void change2(int pos, int val)
{
    for (; pos; pos -= lowbit(pos))tr2[pos] = max(tr2[pos], val);
}
int ask2(int pos)
{
    int res = -inf;
    for (; pos <= tot; pos += lowbit(pos))res = max(res, tr2[pos]);
    return res;
}
int check2(int mid)
{
    tot = 0;
    for (int i = 0; i <= n; ++i)
    {
        b[++tot] = a[i];
        b[++tot] = a[i] - mid;
    }
    sort(b + 1, b + 1 + tot);
    tot = unique(b + 1, b + 1 + tot) - b - 1;
    for (int i = 0; i <= n; ++i)
    {
        t1[i] = lower_bound(b + 1, b + 1 + tot, a[i]) - b;
        t2[i] = lower_bound(b + 1, b + 1 + tot, a[i] - mid) - b;
    }
    for (int i = 1; i <= tot; ++i)tr1[i] = inf, tr2[i] = -inf;
    change1(t1[0], 0); change2(t1[0], 0);
    for (int i = 1; i <= n; ++i)
    {
        f1[i] = ask1(t2[i]) + 1; f2[i] = ask2(t2[i]) + 1;
        change1(t1[i], f1[i]); change2(t1[i], f2[i]);
    }
    return f1[n] <= k && k <= f2[n];
}
void solve2()
{
    int l = 0, r = 0;
    for (int i = 1; i <= n; ++i)
        if (a[i] < 0)l += a[i];
        else r += a[i];
    for (int i = 1; i <= n; ++i)a[i] += a[i - 1];
    while (l <= r)
    {
        int mid = (l + r) / 2;
        if (check2(mid))ans = mid, r = mid - 1;
        else l = mid + 1;
    }
    cout << ans;
}
int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; ++i)a[i] = read();
    solve2();
    return 0;
}

T3生成树求和
由于加法不进位,所以每一位我们单独考虑。
用矩阵树定理求的是\(\sum\)所有生成树边权的积,而这里我们需要求的是边权和,所以三次单位根的乘法来完成加法。
最后还要求解一下三元一次方程,可以选择高斯消元,也可以像我一样手动消元。

#include<iostream>
#include<cstring>
#include<cstdio>
#define int long long
#define LL long long
using namespace std;
int n, m, ans;
const LL N = 105, mod = 1e9 + 7, inv2 = (mod + 1) >> 1, inv3 = (mod + 1) / 3, sqrt3 = 82062379;
int fr[N * N], to[N * N], val[N * N], bin[20];
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;
}
LL ksm(LL a, LL b, LL mod)
{
    LL res = 1;
    for (; b; b >>= 1, a = a * a % mod)
        if (b & 1)res = res * a % mod;
    return res;
}
struct xu
{
    LL a, b;
    xu(int _a = 0, int _b = 0) {a = _a, b = _b;}
    friend xu operator +(const xu &x, const xu &y)
    {return (xu) {(x.a + y.a) % mod, (x.b + y.b) % mod};}
    friend xu operator -(const xu &x, const xu &y)
    {return (xu) {(x.a - y.a + mod) % mod, (x.b - y.b + mod) % mod};}
    friend xu operator *(const xu &x, const xu &y)
    {return (xu) {(x.a * y.a % mod - x.b * y.b % mod + mod) % mod, (x.a * y.b + x.b * y.a) % mod};}
    friend xu operator *(const xu &x, const int &y)
    {return (xu) {(x.a * y) % mod, (x.b * y) % mod};}
    friend xu operator /(const xu &x, const int &y)
    {
        int inv = ksm(y, mod - 2, mod);
        return (xu) {(x.a * inv) % mod, (x.b * inv) % mod};
    }
    friend xu operator /(const xu &x, const xu &y)
    {
        return x * (xu) {y.a, mod - y.b} / ((y.a * y.a % mod + y.b * y.b % mod) % mod);
    }
} w[3], invw[3], a[N][N], coef[3], inv;
xu work()
{
    xu res = xu(1, 0);
    for (int i = 1; i < n; ++i)
    {
        for (int j = i; j < n; ++j)
            if (a[j][i].a || a[j][i].b)
            {
                if (i == j)break;
                swap(a[i], a[j]); res = res * (mod - 1);
                break;
            }
        for (int j = i + 1; j < n; ++j)
        {
            inv = a[j][i] / a[i][i];
            for (int k = i; k < n; ++k)a[j][k] = a[j][k] - inv * a[i][k];
        }
        res = res * a[i][i];
    }
    return res;
}
void solve(xu *p)
{
    xu tmp[3];
    tmp[0] = p[0]; tmp[1] = p[1]; tmp[2] = p[2];
    p[0] = tmp[0] + tmp[1] + tmp[2];
    p[1] = tmp[0] + tmp[1] * invw[1] + tmp[2] * invw[2];
    p[2] = tmp[0] + tmp[1] * invw[2] + tmp[2] * invw[1];
    for (int i = 0; i <= 2; ++i)p[i] = p[i] * inv3;
}
LL suan(int p)
{
    int k;
    xu w0, w1, w2, c;
    for (int i = 0; i <= 2; ++i)
    {
        memset(a, 0, sizeof(a));
        w0 = xu(1, 0); w1 = w[i]; w2 = w[(i + i) % 3];
        for (int j = 1; j <= m; ++j)
        {
            k = val[j] / bin[p] % 3;
            c = (k == 1 ? w1 : (k == 2 ? w2 : w0));
            a[fr[j]][fr[j]] = a[fr[j]][fr[j]] + c;
            a[to[j]][to[j]] = a[to[j]][to[j]] + c;
            a[fr[j]][to[j]] = a[fr[j]][to[j]] - c;
            a[to[j]][fr[j]] = a[to[j]][fr[j]] - c;
        }
        coef[i] = work();
    }
    solve(coef);
    return ((coef[1].a + coef[2].a + coef[2].a) % mod) * bin[p] % mod;
}
signed main()
{
    freopen("sum.in", "r", stdin);
    freopen("sum.out", "w", stdout);
    cin >> n >> m;
    w[0] = xu(1, 0); w[1] = xu(mod - inv2, sqrt3 * inv2 % mod);
    w[2] = xu(mod - inv2, mod - sqrt3 * inv2 % mod);
    invw[0] = xu(1, 0) / w[0]; invw[1] = xu(1, 0) / w[1]; invw[2] = xu(1, 0) / w[2];
    for (int i = 1; i <= m; ++i)fr[i] = read(), to[i] = read(), val[i] = read();
    bin[0] = 1;
    for (int i = 1; i <= 10; ++i)bin[i] = bin[i - 1] * 3;
    for (int i = 0; i <= 10; ++i)(ans += suan(i)) %= mod;
    cout << ans;
    return 0;
}

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

时间: 2024-08-30 12:01:38

2020.1.2考试总结的相关文章

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

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

2020.1.5考试总结

T1和T3不太可做..先只放一下T2 TMD考场上没算好空间直接MLE爆零... 操作1可以归到操作3里,并且几个人的操作可以合并到一块,用线段树挺好维护的. 对于询问的话可以对每一个节点开一个桶,记录区间内前缀数量,向上合并的时候左儿子直接加,右儿子异或后再加. 发现很多节点根本用不到,动态开点即可. #include<iostream> #include<cstring> #include<cstdio> #define lson (k<<1) #def

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 &

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>

2020.3.1考试T1 多项式

出题人很凉心的把算法写成了题目名 首先我们可以发现每一维的贡献是独立的,这可以从 \(solve1\) 里看出来 然后我们可以考虑转化为 \(DP\) ,这可以从 \(solve2\) 里看出来 我们统计每一维能产生的贡献,就是 \(a\) 个 \(0\) 面, \(b\) 个 \(1\) 面, \(c\) 个 \(2\) 面这种形式,能写成一个多项式 \(ax^0+bx^1+cx^2\),而我们最终显然就是把所有的多项式都乘起来. 暴力一个一个乘就很 naive,分治 \(NTT\) 解决就好

2019OKR规划

转眼又一年过去了,回顾审视一年的得失,规划下一年的奋斗目标.Review And Planning,让全新的2019迎来全新的自己. O1 学习软件开发技术知识 KR1.1 阅读<CLR via C#(第四版)> KR1.2 阅读<代码整洁之道> KR1.3 阅读<VUE.js权威指南> KR1.4 阅读Python相关书籍1本 KR1.5 阅读<Microsoft.NET 企业级应用架构设计> KR1.6 阅读<.NET微服务:容器化.NET应用架构

【晨间日记】35计划第0004天(191206)

晨间日记:35计划第0004天(191206) 一.三早 1.早睡:11:30 2.早起:07:00 3.早读:英语口语练习.单词背诵 二.每日基础 1.晨间日记:每日早上写. 2.每日博客:每天至少写一篇博客(博客园.CSDN.简书). 3.每日学习:每天职业技能书籍至少学习一章. 4.每日阅读:每天阅读技术类博客 30 - 60 分钟. 5.学习计划:<操作系统>学习. 6.工作学习:PowerShell 学习. 三.昨日总结 1.晨间日记:完成 2.每日博客:[黑客基础]Windows

2020奕诚国家电网考试资料全套视频

链接:https://pan.baidu.com/s/1npAYuq7Yg6zSrdiQ55oVyA 提取码:ub4t 复制这段内容后打开百度网盘手机App,操作更方便哦 2020奕诚国家电网考试视频资料 综合(行测)(高清完整版) 2020奕诚国家电网考试视频资料 电路(高清完整版) 2020奕诚国家电网考试视频资料电工类 电分(高清完整版) 2020奕诚国家电网考试视频资料 继保(高清完整版) 2020奕诚国家电网考试视频资料 龙腾分科测试题讲解 电路 (高清完整版) 2020奕诚国家电网考

2020年出版专业技术人员职业资格考试,历年真题,考前复习,考试大纲,视频课程

各出版社.期刊社.新媒体单位.网络出版单位: 从2001年8月1日起,国家对出版专业技术人员实行职业资格制度,纳入全国专业技术人员职业资格制度的统一规划.同时在2016年3月10日,由国家新闻出版广电总局.中华人民共和国工业和信息化部联合发布的<网络出版服务管理规定>中,第二章第九条明确规定,从事网络出版服务单位,必须有8名以上具有<中华人民共和国出版专业技术人员职业资格证书>人员,其中中级以上人员不少于3名.<中华人民共和国出版专业技术人员职业资格证书>是传统出版行业