码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces Round #544 Div.3

时间:2019-04-22 15:10:19      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:ant   font   gcd   tin   map   print   vector   blank   second   

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

代码:

技术图片
#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

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

 

 

 

技术图片

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

CodeForces Round #544 Div.3

标签:ant   font   gcd   tin   map   print   vector   blank   second   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!