[luogu#2019/03/10模拟赛][LnOI2019]长脖子鹿省选模拟赛赛后总结

t1-快速多项式变换(FPT)

题解

看到这个\(f(x)=a_0+a_1x+a_2x^2+a_3x^3+ \cdots + a_nx^n\)式子,我们会想到我们学习进制转换中学到的,那么我们就只需要\(m\)转换成\(n\)进制就可以了。

ac代码

#include <bits/stdc++.h>
using namespace std;
long long n, m, a[1005];
int cnt;
int main() {
    cin >> n >> m; 
    while (m > 0) {
        a[ ++ cnt] = m % n;
        m /= n;
    }
    printf("%d\n", cnt);
    for (int i = 1; i <= cnt; i ++) printf("%lld ", a[i]);
    return 0;
}

t2-加特林轮盘赌

题解

我们假设f[2][1]表示最后一个人最终幸存的概率,那么f[2][2]表示第二个最终幸存的概率。
\[f[2][1]=p0*0+(1-p0)*f[2][2]\]
作为一个二元一次方程,我们还需要一个等式接触他们不难想到两个概率的和一定是\(1\)
\[f[2][1]+f[2][2]=1\]
以此类推到k个人,其中两个式子就是和之前一样的。
\[f[n][1]=(1-p0)*f[n][n]\]
\[f[n][1]+f[n][2]+...f[n][n]=1\]
当前我们在崩第一个玩家时,那么排在k的玩家会怎么样?
概率\(1-p0\):如果第一个玩家没死,那么就相当于是换了一个起点
\[f[n][k]->f[n][k-1]\]
概率\(1-p0\):每次,那么每一个人还是往前走了一步,只不过是人数少了一个:
\[f[n][k]->f[n-1][k-1]\]
所以我们可以通过以下等式退出n个等式
\[f[n][k]=p0*f[n][k-1]+(1-p0)*f[n-1][k-1]\]
那么最后只有一个幸存者,那么所以\(\sum^n_{k=1} f[n][k]=1\),接触这个方程,手动消元满分,还要特判以下,当\(p0\)为0时,答案是\(0\)

ac代码

#include <bits/stdc++.h>
#define db double 
#define N 100005
using namespace std;
db f[2][N];
int n, k;
db p0;
int main() {
    cin>> p0>> n>> k;
    if (p0 == 0){
        printf("%.10lf\n",0.0);
        return 0;
    }
    f[1][1] = 1;
    for (int i = 2; i <= n; i ++) {
        db rate = 1, tmp = 0;
        for (int j = 0; j <= i - 2; j ++) {
            tmp += rate * f[(i - 1) % 2][i - j - 1];
            rate *= (1 - p0);
        }
        rate *= (1 - p0);
        tmp *= p0; 
        tmp /= (1 - rate);
        f[i % 2][1] = (1 - p0) * tmp;
        for (int j = 2; j <= i; j ++) 
            f[i % 2][j] = (1 - p0) * f[i % 2][j - 1] + p0 * f[(i - 1) % 2][j - 1];
        f[i % 2][i] = tmp;
    }
    printf("%.10lf\n",f[n % 2][k]);
    return 0;
}

t3-东京夏日相会

题解

我们将一个圆上的点拆成精度差在与题目中规定的0.01。在官方题解中说明:可以证明当d≤acos(1−0.005/r) 时所得的答案与标准答案差距不超过 0.01 .证明是初中基础数学请各位自己推一下。
那么完成拆点之后就是最小点覆盖的模板了。

ac代码

#include <bits/stdc++.h>
#define N 20000005
#define db double 
#define PI acos(-1)
using namespace std;
struct Point {
    db x, y;
}a[N], o;
const db eps = 1e-4;
int tot, n;
db ri;
void create_point(db x, db y, db r) {
    if (r == 0) a[++ tot] = (Point){x, y};
    else {
        db delta = max(360 * acos(1 - 0.004 / r) / PI, 1.0);
        for (int i = 0; i < 360; i += delta) {
            db alpha = i * PI / 180;
            a[++ tot] = (Point){x + r * cos(alpha), y + r * sin(alpha)};
        }
    }
}
db calc(Point a, Point b) {
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
void three_point(Point p1, Point p2, Point p3) {
    db a = p2.y - p1.y, b = p3.y - p1.y, c = p2.x - p1.x, d = p3.x - p1.x, e = p2.x * p2.x + p2.y * p2.y - p1.x * p1.x - p1.y * p1.y, f = p3.x * p3.x + p3.y * p3.y - p1.x * p1.x - p1.y * p1.y ;
    o.x = (a * f - b * e) / (2 * a * d - 2 * b * c);
    o.y = (d * e - c * f) / (2 * a * d - 2 * b * c);
    ri = calc(o, p1);
}
int main() {
    scanf("%d", &n);
    tot = 0;
    for (int i = 1; i <= n; i ++) {
        db x, y, r;
        scanf("%lf%lf%lf", &x, &y, &r);
        create_point(x, y, r);
    }
    random_shuffle(a + 1, a + 1 + tot);
    o = a[1]; ri = 0;
    for (int i = 2; i <= tot; i ++) {
        if (calc(a[i], o) > ri + eps) {
            o = a[i]; ri = 0;
            for (int j = 1; j <= i - 1; j ++) {
                if (calc(o, a[j]) > ri + eps) {
                    o.x = (a[i].x + a[j].x) / 2;
                    o.y = (a[i].y + a[j].y) / 2;
                    ri = calc(o, a[j]);
                    for (int k = 1; k <= j - 1; k ++) {
                        if (calc(o, a[k])>ri + eps) three_point(a[i], a[j], a[k]);
                    }
                }
            }
        }
    }
    printf("%.2lf %.2lf %.2lf\n", o.x, o.y, ri);
    return 0;
}

t4-第二代图灵机

解法

我不会,咕咕掉了。

官方ac代码

//T4 std By Sinon
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <bitset>
#include <cstdlib>
#define IT set<node>::iterator
using namespace std;
const int MAXM = 150, MAXN = 100050;

void read(int &x){
    char ch;
    while(ch = getchar(), ch < '!'); x = ch - 48;
    while(ch = getchar(), ch > '!') x = (x << 3) + (x << 1) + ch - 48;
}

void write(int x) {if(x > 9) write(x / 10); putchar(x % 10 + 48);}

struct node {
    int l, r;
    mutable int v;
    node(int L, int R = -1, int V = 0) : l(L), r(R), v(V) {}
    bool operator < (const node &o) const {
        return l < o.l;
    }
};

set <node> s;
int n, m, q, ap[MAXM], t[MAXN], tree[MAXN << 2], w[MAXN];
bool apt[MAXM];

int lowbit(int x) {return x & (-x);}

void update(int x, int val) {
    for(; x <= n; t[x] += val, x += lowbit(x));
}
int query(int x) {
    int res = 0;
    for(; x > 0; res += t[x], x -= lowbit(x));
    return res;
}
int ask(int l, int r) {return query(r) - query(l-1);}


void pushup(int i){tree[i] = max(tree[i << 1], tree[i << 1 | 1]);}
 
void updatemax(int i, int l, int r, int x, int val) {
    if (l == r) {tree[i] = val; return;}
    int mid = (l + r) / 2;
    if (x <= mid) updatemax(i << 1, l, mid, x, val);
    else updatemax(i << 1 | 1, mid + 1, r, x, val);
    pushup(i);
}
 
int querymax(int i, int l, int r, int x, int y) {
    if (x <= l && r <= y) return tree[i];
    int mx = 0, mid = (l + r) / 2;
    if (x <= mid) mx = max(mx, querymax(i << 1, l, mid, x, y));
    if (y > mid) mx = max(mx, querymax(i << 1 | 1, mid + 1, r, x, y));
    return mx;
}

IT spilit (int pos) {
    IT it = s.lower_bound(node(pos));
    if(it != s.end() && it->l == pos) return it;
    it--;
    int L = it -> l, R = it -> r;
    int V = it->v;
    s.erase(it);
    s.insert(node(L, pos-1, V));
    return s.insert(node(pos, R, V)).first;
}

void assign(int l, int r, int val = 0) {
    IT ir = spilit(r+1), il = spilit(l);
    s.erase(il, ir);
    s.insert(node(l, r, val));
}

int query1(int l, int r) {
    int ans = 2147483647, lef; memset(ap, 0, sizeof ap);
    IT ir = spilit(r+1), il = spilit(l), L, R; --il;
    L = R = il; lef = m;
    while(R != ir) {
        if(L != il) {--ap[L->v]; if(!ap[L->v]) ++lef;} ++L;
        while(lef && R != ir) {++R; ++ap[R->v]; if(ap[R->v] == 1) --lef;}
        if(R == ir) break;
        while(!lef && L != R) {--ap[L->v]; if(!ap[L->v]) ++lef; ++L;} 
        if(lef) {--L; ++ap[L->v]; --lef;}
        ans = min(ask(L->r, R->l), ans);
    }
    return ans;
}

int query2(int l, int r) {
    memset(apt, 0, sizeof apt);
    int ans = querymax(1, 1, n, l, r);
    IT ir = spilit(r+1), il = spilit(l), R, L;
    R = il; --il; L = il;
    while(R != ir) {
        if(L != il) apt[L->v] = 0; ++L;
        apt[L->v] = 1;
        while(R->l < L->r) ++R;
        if(L == R) ++R;
        if(R == ir) break;
        while(!apt[R->v] && R != ir && R->l == R->r) {apt[R->v] = 1; ++R;}
        if(R == ir) --R;
        else if(!apt[R->v]) apt[R->v] = 1; else --R;
        if(L == R) continue;
        //cout << L->r << " " << R->l << endl;
        ans = max(ans, ask(L->r, R->l));
    }
    return ans;
}

int main() {
    read(n); read(q); read(m);
    s.insert(node(0, 0, -1)); s.insert((n+1, n+1, -1));
    for(int x, i = 1; i <= n; ++i) read(x), update(i, x), updatemax(1, 1, n, i, x);
    for(int x, i = 1; i <= n; ++i) read(x), s.insert(node(i, i, x));
    int opt, l, r, x;
    while(q--) {
        read(opt);
        if(opt == 1) {
            read(l); read(r);
            update(l, r - ask(l, l));
            updatemax(1, 1, n, l, r);
        } else if(opt == 2) {
            read(l); read(r); read(x);
            assign(l, r, x);
        } else if(opt == 3) {
            read(l); read(r);
            int ans = query1(l, r);
            if(ans == 2147483647) puts("-1"); 
            else write(ans), putchar('\n');
        } else if(opt == 4) {
            read(l); read(r);
            write(query2(l, r)); putchar('\n');
        }
    }
}
posted @ 2019-03-14 14:17 chhokmah 阅读(...) 评论(...) 编辑 收藏