Codeforces Round #546 (Div. 2)

http://codeforces.com/contest/1136

A

#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5 + 10;
int N, K;

struct Node {
    int L;
    int R;
}node[maxn];

int main() {
    scanf("%d", &N);
    for(int i = 1; i <= N; i ++)
        scanf("%d%d", &node[i].L, &node[i].R);
    scanf("%d", &K);

    int cnt = 0;
    for(int i = 1; i <= N; i ++) {
        if(node[i].R >= K) cnt ++;
        else continue;
    }

    printf("%d\n", cnt);

    return 0;
}

B

#include <bits/stdc++.h>
using namespace std;

int N, K;

int main() {
    scanf("%d%d", &N, &K);
    int ans = 0;
    ans = 3 * N + min(K - 1, N - K);
    printf("%d\n", ans);
    return 0;
}

C

D

#include <bits/stdc++.h>
using namespace std;

const int maxn = 3e5 + 10;
vector<int> v[maxn];
int N, M;
int num[maxn], ans[maxn];

int main() {
    scanf("%d%d", &N, &M);
    for(int i = 1; i <= N; i ++)
        scanf("%d", &num[i]);
    while(M --) {
        int uu, vv;
        scanf("%d%d", &uu, &vv);
        v[vv].push_back(uu);
    }

    for(int i = 0; i < v[num[N]].size(); i ++)
        ans[v[num[N]][i]] ++;

    int cnt = 0;
    for(int i = N - 1; i >= 1; i --) {
        if(ans[num[i]] == N - i - cnt) cnt ++;
        else {
            for(int j = 0; j < v[num[i]].size(); j ++)
                ans[v[num[i]][j]] ++;
        }
    }

    printf("%d\n", cnt);
    return 0;
}

很久没更新了 最近和队友训练准备这样那样的比赛 写完题好像也没贴 哭唧唧 会尽快把之前做的题总结一下发上来的 养肥我的 Be 客

FH

原文地址:https://www.cnblogs.com/zlrrrr/p/10537542.html

时间: 2024-08-30 12:49:44

Codeforces Round #546 (Div. 2)的相关文章

Nastya Hasn&#39;t Written a Legend(Codeforces Round #546 (Div. 2)E+线段树)

题目链接 传送门 题面 题意 给你一个\(a\)数组和一个\(k\)数组,进行\(q\)次操作,操作分为两种: 将\(a_i\)增加\(x\),此时如果\(a_{i+1}<a_i+k_i\),那么就将\(a_{i+1}\)变成\(a_i+k_i\),如果\(a_{i+2}<a_i+k_i\),则将\(a_{i+2}\)变成\(a_{i+1}+k_{i+1}\),以此类推. 查询\(\sum\limits_{i=l}^{r}a_i\). 思路 我们首先存下\(k\)数组的前缀和\(sum1\),

Codeforces Round #546 (Div. 2) D 贪心 + 思维

https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则,假如u在v相邻前面,那么u和v可以交换位置,问你是队列最后一个人的时候你最前可以换到前面哪里 题解 因为相邻才能换,所以最后一个换到前面一定是一步一步向前走,所以不存在还要向后走的情况 设最后一个为u,假设前面有一个能和u换位置的集合,那么需要将这些点尽量往后移动去接u 假设前面有一个不能和u换位置的集合S,

Codeforces Round #546 (Div. 2) C. Nastya Is Transposing Matrices

C. Nastya Is Transposing Matrices time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Nastya came to her informatics lesson, and her teacher who is, by the way, a little bit famous here gave he

Codeforces Round #546 (Div. 2) D. Nastya Is Buying Lunch

题意: 长度为n的数组{pi},m对关系(a,b),如果a正好在数组中位于b的前一个位置,则可以交换a和b,问最多可以让pn的位置往前移动多少 题解: 如果pn可以往前走k步,他肯定可以和pk交换.如果pk后面的数都可与他交换,则最后可以使pn和pk互换,使pn移动到pk的位置 #include <bits/stdc++.h> //#pragma comment(linker, ”/STACK:36777216“) using namespace std; typedef long long

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

Codeforces Round #273 (Div. 2)

Codeforces Round #273 (Div. 2) 题目链接 A:签到,仅仅要推断总和是不是5的倍数就可以,注意推断0的情况 B:最大值的情况是每一个集合先放1个,剩下都丢到一个集合去,最小值是尽量平均去分 C:假如3种球从小到大是a, b, c,那么假设(a + b) 2 <= c这个比較明显答案就是a + b了.由于c肯定要剩余了,假设(a + b)2 > c的话,就肯定能构造出最优的(a + b + c) / 3,由于肯定能够先拿a和b去消除c,而且控制a和b成2倍关系或者消除