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\n", 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\n", 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\n", maxx);

    return 0;
}
View Code

D. Zero Quantity Maximization

不敢相信现在会因为数组开小 wa 了四发 2e5 被我开成 1e5 我都不知道我这四次在改什么 是猪吧

代码:

#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\n", maxx + cnt);

    return 0;
}
View Code

E. K Balanced Teams

代码:

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

const int maxn = 5050;
int N, K;
int a[maxn], dp[maxn][maxn];

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

    sort(a + 1, a + N + 1);
    memset(dp, 0, sizeof(dp));
    int pos = 1;
    for(int i = 1; i <= N; i ++) {
        while(a[i] - a[pos] > 5 && pos <= N) pos ++;
        for(int j = 1; j <= min(K, i); j ++) {
            dp[i][j] = max(dp[i - 1][j], dp[pos - 1][j - 1] + i - pos + 1);
        }
    }

    int ans = 0;
    for(int i = 1; i <= K; i ++) {
        ans = max(ans, dp[N][i]);
    }

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

    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\n", 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

 F2. Spanning Tree with One Fixed Degree

 

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

posted @ 2019-04-22 15:03  丧心病狂工科女  阅读(106)  评论(0编辑  收藏  举报