ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Codeforces Round #549 (Div. 1)

2019-04-10 22:50:42  阅读:259  来源: 互联网

标签:Node 549 return int top Codeforces long Div include


今天试图用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;   
}

标签:Node,549,return,int,top,Codeforces,long,Div,include
来源: https://www.cnblogs.com/hjmmm/p/10686719.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有