首页 > 其他分享 >Educational Codeforces Round 7

Educational Codeforces Round 7

时间:2022-12-29 12:24:15浏览次数:60  
标签:std Educational include int Codeforces long using main Round

Educational Codeforces Round 7

https://codeforces.com/contest/622/problems
3/6: ABD

A. Infinite Sequence

水题

#include <bits/stdc++.h>

using namespace std;

int main () {
    long long x;
    cin >> x;
    long long n = sqrt (2 * x), m = (n + 1) * n / 2;
    //cout << m << ' ';
    if (x <= m) {
        cout << n - (m - x);
    }
    else {
        cout << x - m;
    }
}

B. The Time

水题

#include <bits/stdc++.h>

using namespace std;

int main () {
    int hh, mm, dx;
    scanf ("%d:%d", &hh, &mm);
    scanf ("%d", &dx);
    //cout << hh << ' ' << mm << ' ' << dx << endl;
    mm += dx;
    hh += mm / 60, mm %= 60, hh %= 24;
    //cout << hh << ' ' << mm;
    cout << setw(2) << setfill('0') << hh  << ':';
    cout << setw(2) << setfill('0') << mm << endl;
}

C. Not Equal on a Segment

这题思路很难想,个人想不到pos[]数组要这样做
一开始二分找,超时了

#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 5, M = 1e6 + 5;
int a[N], n, m;
int pos[N]; //i前面第一个相同的的下标

int main () {
    scanf ("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
        scanf ("%d", &a[i]);
        if (a[i] == a[i-1])     pos[i] = pos[i-1];
        else    pos[i] = i;
    }
    while (m --) {
        int l, r, x;
        scanf ("%d%d%d", &l, &r, &x);
        if (a[r] != x)  printf ("%d\n", r);
        else {
            if (pos[r] <= l) printf ("-1\n");
            else   printf ("%d\n", pos[r] - 1);
        }
    }
}

//找到[l,r]区间内不等于x的数的下标
//[1,1e6]

D. Optimal Number Permutation

非常开心!做出了一道1900
构造题,观察式子:

\(i,n\)都是固定的,所以就想一下怎么安排能够使得 \(d_i\) 的值近可能靠近 \(n-i\)。不妨设两个 \(i\) 之间的距离间隔即 \(d_i=n-i\),则可以像下图一样构造:
(最后的 \(n\) 无论如何摆放贡献都是0,所以只需补最后一位的空即可)

#include <bits/stdc++.h>

using namespace std;
const int N = 5e5 + 5, M = N * 2;
int n, a[M];

int main () {
    cin >> n;
    for (int i = 1, j = 1; i <= n; i += 2, j++)    a[j] = a[n-j+1] = i;
    for (int i = 2, j = 1; i <= n; i += 2, j++)    a[n+j] = a[2*n-j] = i;
    a[2 * n] = n;
    for (int i = 1; i <= 2 * n; i++)    cout << a[i] << ' ';
}

/*
1: 1,   n
2: n+1, 2*n-1
3: 2,   n-1
4: n+2, 2n-2
...
*/

E. Ants in Leaves

F. The Sum of the k-th Powers

标签:std,Educational,include,int,Codeforces,long,using,main,Round
From: https://www.cnblogs.com/CTing/p/17012138.html

相关文章

  • Codeforces Round #841 (Div. 2) and Divide by Zero 2022
    Preface这场Div2怎么感觉难度和Div3一样,ABCD都是SB题一眼秒,可惜D下标\(n,m\)弄混挂了一发E本来也是秒出的正解,但是实现的时候一个细节挂了(自作聪明,后来结束前5min改出来......
  • Codeforces Round #841 (Div. 2) and Divide by Zero 2022
    《C.EvenSubarrays》异或和,前缀和  这道题如果用朴素的暴露解法为O(n^2),算出每一个子段的异或和,然后看一下这些异或和中哪个的除数是奇数个,但会超时 超时原因明......
  •   Codeforces Round #841 (Div. 2) and Divide by Zero 2022 -----C. Even Subarray
    题目链接:https://codeforces.com/contest/1731/problem/C  题目的大致意思是:给长度为n的数组,求 子数组的异或和  的结果的除数个数为偶数个的子数组有多......
  • Codeforces Round #841 (Div. 2) and Divide by Zero 2022
    CodeforcesRound#841(Div.2)andDividebyZero2022o(╥﹏╥)o2022的最后一场也没打好B题反正我是理解错了,我看到题目上写着要相乘再取模,结果就真的去先乘再取模,这......
  • Codeforces Round #841 (Div. 2) and Divide by Zero 2022
    A.JoeyTakesMoney题意:给定n个整数,每次操作可以选择两个整数,获得两数之积,再构造一组(x,y)使得x*y等于两数之积,并将原来的数替换为x,y,求操作若干次后n个数......
  • Educational DP Contest I - Coins(概率DP)
    https://atcoder.jp/contests/dp/tasks/dp_i题目大意:给定n个硬币,n是奇数,每个硬币朝上的概率是ai问我们一半以上的硬币处于正面的概率是多少?SampleInput130.30......
  • CodeForces-690#D1 题解
    正文很显然啊,这是在考一个叫连通块的东东,于是蒟蒻的我马上想到了连通块必备:并查集。如果一个块四边连通了其它的块,那么合并这两个块。当然,并查集要用二维的:typedefpai......
  • Codeforces Round #767 (Div. 2)C ,D
    CodeforcesRound#767(Div.2)C,DCC这一道题大意是给你一个数组,你可以选取任意长度的数组(连续),求出这个数组的mex,然后问我们你得到最大的字典序的mex是多少(我这里犯......
  • Codeforces Global Round 14 C. Phoenix and Towers(思维)
    https://codeforces.com/contest/1515/problem/C题目大意:给定一个长度为n的序列a,ai表示方块的高度。每一个方块的高度都在1和q之间。让我们用这n个方块搭建m座塔,两两......
  • Codeforces Round #768 (Div. 2)C ,D
    CodeforcesRound#768(Div.2)C,DCC这一道题的大意是从0到n-1,(n一定是2的x次方),我需要找n/2对数对,使得每一个数对(x,y),x&y的和要等于k(k<=n-1)我一开始是没什么思路的,......