Codeforces Round #549 (Div. 1)

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

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

时间: 2024-07-29 00:54:00

Codeforces Round #549 (Div. 1)的相关文章

Codeforces Round #549 (Div. 2) D 数学

https://codeforces.com/contest/1143/problem/D 题意 有nk个城市,第1,k+1,2k+1,...,(n-1)k+1城市有餐厅,你每次能走l距离,a为起始位置离最近餐厅的距离,b为走了一次后离最近餐厅的距离,给出n,k,a,b,求你回到起点最少和最多停留次数 题解 \(yl=xnk,有y=xnk/l,即y=lcm(xnk,l)/l\) 枚举a(两种情况),b(两种情况),维护最大,最小值 代码 #include<bits/stdc++.h> #def

Codeforces Round #549 (Div. 2) F 数形结合 + 凸包(新坑)

https://codeforces.com/contest/1143/problem/F 题意 有n条形如\(y=x^2+bx+c\)的抛物线,问有多少条抛物线上方没有其他抛物线的交点 题解 \(y=x^2+bx+c=>y+x^2=bx+c\),转换为点\((x,y+x^2)\)在bx+c的直线上 两个点确定一条抛物线,同时也确定了一条直线 需要选择最上面那些点相邻确定的抛物线,所以维护一个上凸包即可 维护上凸包,当前点在前进方向左边需要向后退,cross(a,b)>=0 代码 #inclu

Codeforces Round #549 (Div. 2)

A.The Doors 记录最后一个0和1的位置. B.Nirvana 对于每一位,答案有三种情况: 1,取这位原本数字; 2,取x-1,同时让后一位取9; 3,让前面全取9; C.Queen 一个点如果会被删,那么其他的点被删不会影响它最后被删的结果,判断一下那些点会被删, 然后排序. D.The Beatles 显然\( L = c \times k + a - b \) 或 \( L = c \times k - a - b \),对于每个L,\[ step = lcm(n \times

B. Nirvana Codeforces Round #549 (Div. 2) (递归dfs)

---恢复内容开始--- Kurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater value of the product makes the nirvana deeper. Help Kurt find the maximum possible product of digits among all integers from 1 to n. Input

C. Queen Codeforces Round #549 (Div. 2) (搜索)

---恢复内容开始--- You are given a rooted tree with vertices numerated from 11 to nn . A tree is a connected graph without cycles. A rooted tree has a special vertex named root. Ancestors of the vertex ii are all vertices on the path from the root to the v

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我

[Codeforces] Round #352 (Div. 2)

人生不止眼前的狗血,还有远方的狗带 A题B题一如既往的丝帛题 A题题意:询问按照12345678910111213...的顺序排列下去第n(n<=10^3)个数是多少 题解:打表,输出 1 #include<bits/stdc++.h> 2 using namespace std; 3 int dig[10],A[1005]; 4 int main(){ 5 int aa=0; 6 for(int i=1;;i++){ 7 int x=i,dd=0; 8 while(x)dig[++dd