CodeForces Round #544 Div.3

Posted zlrrrr

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces Round #544 Div.3相关的知识,希望对你有一定的参考价值。

A. Middle of the Contest

代码:

技术图片
#include <bits/stdc++.h>
using namespace std;

int h1, m1, h2, m2;
int tim1 = 0, tim2 = 0;

int main() {
    scanf("%d:%d", &h1, &m1);
    scanf("%d:%d", &h2, &m2);

    tim1 = h1 * 60 + m1;
    tim2 = h2 * 60 + m2;

    tim2 -= tim1;
    tim2 /= 2;
    tim1 += tim2;

    int h3 = tim1 / 60, m3 = tim1 % 60;
    printf("%02d:%02d
", h3, m3);

    return 0;
}
View Code

B. Preparation for International Women‘s Day

代码:

技术图片
#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5 + 10;
int N, K;
int a[maxn], vis[110];

int main() {
    scanf("%d%d", &N, &K);
    int ans = 0, cnt = 0;
    for(int i = 1; i <= N; i ++) {
        int x;
        scanf("%d", &x);
        if(x % K == 0) ans ++;
        else vis[x % K] ++;
    }

    ans /= 2;

    for(int i = 1; i <= K / 2; i ++) {
        if(i * 2 != K) ans += min(vis[i], vis[K - i]);
        else ans += (vis[i] / 2);
    }

    printf("%d
", ans * 2);
    return 0;
}
View Code

C. Balanced Team

代码:

技术图片
#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5 + 10;
int N;
int a[maxn];

int main() {
    scanf("%d", &N);
    for(int i = 0; i < N; i ++)
        scanf("%d", &a[i]);

    sort(a, a + N);

    int maxx = 0;
    int l = 0, r = 0;
    while(l <= r && r < N && l < N) {
        while(a[r] - a[l] <= 5 && r < N) r ++;
        maxx = max(maxx, r - l);
        l ++;
    }

    printf("%d
", maxx);

    return 0;
}
View Code

D. Zero Quantity Maximization

代码:

技术图片
#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5 + 10;
int N;
int a[maxn], b[maxn];
map<pair<int, int> , int> mp;

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

int main() {
    scanf("%d", &N);
    for(int i = 0; i < N; i ++)
        scanf("%d", &a[i]);

    int cnt = 0, maxx = 0;
    mp.clear();
    for(int i = 0; i < N; i ++) {
        scanf("%d", &b[i]);
        if(a[i] == 0) {
            if(b[i] == 0) cnt ++;
            continue;
        }
        int t = gcd(a[i], b[i]);
        pair<int, int> p;
        p.first = a[i] / t, p.second = b[i] / t;
        if(p.first < 0) p.first *= -1, p.second *= -1;
        mp[p] ++;
        maxx = max(maxx, mp[p]);
    }

    printf("%d
", maxx + cnt);

    return 0;
}
View Code

F1. Spanning Tree with Maximum Degree

代码:

技术图片
#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5 + 10;
int N, M;
vector<int> v[maxn];
int vis[maxn], son[maxn];
int maxx = 0, temp;
vector<int> u;
vector<vector<int> > ans;

void bfs(int st) {
    vis[st] = 1;
    queue<int> q;
    while(!q.empty()) q.pop();
    q.push(st);
    while(!q.empty()) {
        int tp = q.front();
        q.pop();
        for(int i = 0; i < v[tp].size(); i ++) {
            if(!vis[v[tp][i]]) {
                vis[v[tp][i]] = 1;
                printf("%d %d
", tp, v[tp][i]);
                q.push(v[tp][i]);
            }
        }
    }
}

int main() {
    scanf("%d%d", &N, &M);
    while(M --) {
        int a, b;
        scanf("%d%d", &a, &b);
        v[a].push_back(b);
        v[b].push_back(a);
        son[a] ++, son[b] ++;
    }

    for(int i = 1; i <= N; i ++) {
        if(son[i] > maxx) {
            maxx = son[i];
            temp = i;
        }
    }

    bfs(temp);
    return 0;
}
View Code

 

 

 

技术图片

今天也是被奶茶治愈的一天 FH 

以上是关于CodeForces Round #544 Div.3的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #544 (Div. 3) C. Balanced Team [暴力剪枝]

Codeforces Round #544 (Div. 3) dp + 双指针

Codeforces Round #705 (Div. 2)

Codeforces Round #774 (Div. 2)

Codeforces Round #808 (Div. 1)(A~C)

Codeforces Round #717 (Div. 2)