码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #549 (Div. 1)

时间:2019-04-10 23:28:08      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:fabs   amp   抛物线   排列   tps   The   class   play   blog   

今天试图用typora写题解

真开心

参考

你会发现有很多都是参考的。。zblzbl

Codeforces Round #549 (Div. 1)

最近脑子不行啦 需要cf来缓解一下

A. The Beatles

这道题就是枚举啦 有两种步长 试一下就好了

如果你的步长是x

那么要跳的次数就是距离除以步长
\[ \frac{n * k * x}{gcd(n * k, x)} \div x = \frac{n * k}{gcd(n * k, x)} \]

#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <complex>
#include <ctime>
#include <queue>
using namespace std;
long long n, m, a, b;
long long mxx, mnn;

long long gcd(long long x,long long y){
    return y ? gcd(y, x % y) : x;
}

void solve(long long x){
    for(int i = 1; i <= n; ++i){
        mxx = max(mxx, gcd(x, n * m));
        mnn = min(mnn, gcd(x, n * m));
        x += m;
    }
}

int main(){
    scanf("%lld%lld%lld%lld", &n, &m, &a, &b);
    if(a < b) swap(a, b);
    mxx = 1, mnn = n * m;
    solve(a - b); solve(m - a - b);
    printf("%lld %lld\n", n * m / mxx, n * m / mnn); 
    return 0;   
}

B. Lynyrd Skynyrd

这道题不用主席树啊喂

向前跳够n - 1个前驱就可以

(前驱就是前面最近的 值在排列里位于前一位的 数

倍增维护一下

#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <complex>
#include <ctime>
#include <queue>
using namespace std;

/*
记录每个点的pre 然后维护前面第n-1个pre
*/
const int N = 2e5 + 5;
int n, m, q;
int fro[N], pre[N][25], rec[N], mx[N];
int a[N], b[N], rt[N];

int main(){
    scanf("%d%d%d", &n, &m, &q);
    for(int i = 1; i <= n; ++i){
        scanf("%d", &a[i]);
        fro[a[i]] = a[i - 1];
    } 
    fro[a[1]] = a[n];
    for(int i = 1; i <= m; ++i){
        scanf("%d", &b[i]);
        pre[i][0] = rec[fro[b[i]]], rec[b[i]] = i;
        for(int j = 1; j <= 20; ++j)
            pre[i][j] = pre[pre[i][j - 1]][j - 1];
        int pos = i;
        for(int j = 20; j >= 0; --j)
            if((1 << j) & (n - 1)){
                pos = pre[pos][j];
            } 
        mx[i] = max(mx[i - 1], pos);
    }
    for(int i = 1, x, y; i <= q; ++i){
        scanf("%d%d", &x, &y);
        printf("%d", mx[y] >= x);
    }
    return 0;   
}

C. U2

这道题真的是完全不会。。学到了学到了。。

如果点(x0, y0)在抛物线下的话

把式子拆一波
\[ x_0^2 + bx_0 + c \geq y_0 \]

\[ bx_0 + c \geq -x_0^2 + y_0 \]

然后你会惊讶地发现左边是一个直线方程(废话

这个直线的意义就是 如果这个直线过一个点的话

那么那条抛物线也过它

如果这条直线在那个点上方的话 那么那个点在抛物线外

现在就是一个上凸壳问题

#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <complex>
#include <ctime>
#include <queue>
using namespace std;

/*
记录每个点的next 然后维护前面第n-1个pre
*/
const double eps = 1e-9;
const int N = 1e5 + 5;
struct Node{
    double x, y;
    void init(){y = y - x * x;}
    friend Node operator -(Node a, Node b){
        return (Node){a.x - b.x, a.y - b.y};
    }
}node[N], stk[N];
int n, top; 
inline double cross(Node x, Node y){
    return x.x * y.y - x.y * y.x;
}
inline bool rule(Node x, Node y){
    return fabs(x.x - y.x) < eps ? x.y < y.y : x.x < y.x; 
}

int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i){
        scanf("%lf%lf", &node[i].x, &node[i].y);
        node[i].init();
    }
    sort(node + 1, node + n + 1, rule);
    for(int i = 1; i <= n; ++i){
        //无论是水平还是述职都要忽略 
        if(top && fabs(stk[top].x - node[i].x) < eps) --top;
        while(top > 1 && cross(node[i] - stk[top - 1], stk[top] - stk[top - 1]) < eps) --top;
        stk[++top] = node[i];
    }
    printf("%d", top - 1);
    return 0;   
}

Codeforces Round #549 (Div. 1)

标签:fabs   amp   抛物线   排列   tps   The   class   play   blog   

原文地址:https://www.cnblogs.com/hjmmm/p/10686719.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!