现在的位置: 首页 > 综合 > 正文

Codeforces Round #281(Div2)

2019年02月11日 ⁄ 综合 ⁄ 共 2620字 ⁄ 字号 评论关闭

A - Vasya and Football

#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
using namespace std;
#define MAXN 100

char away[28], home[28];
int pa[MAXN], ph[MAXN], n;
bool visa[MAXN], vish[MAXN];

struct Message
{
    int time, id;
    char team[4], color[4];
    Message() {}
    void in()
    {
        scanf("%d %s %d %s", &time, team, &id, color);
    }
    bool operator <(const Message &argu) const
    {
        return time < argu.time;
    }
}mm[MAXN];

int main()
{
//    freopen("A.in", "r", stdin);

    scanf("%s%s", home, away);
    scanf("%d", &n);

    memset(pa, 0, sizeof(pa));
    memset(ph, 0, sizeof(ph));

    memset(visa, false, sizeof(visa));
    memset(vish, false, sizeof(vish));

    for(int i = 0; i < n; i++)
        mm[i].in();
    sort(mm, mm + n);

    for(int i = 0; i < n; i++)
    {
        if(strcmp(mm[i].team, "a") == 0)
        {
            if(strcmp(mm[i].color, "y") == 0)
                pa[mm[i].id]++;
            else
                pa[mm[i].id] += 2;
            if(pa[mm[i].id] >= 2 && !visa[mm[i].id])
            {
                visa[mm[i].id] = true;
                printf("%s %d %d\n", away, mm[i].id, mm[i].time);
            }
        }
        else
        {
            if(strcmp(mm[i].color, "y") == 0)
                ph[mm[i].id]++;
            else
                ph[mm[i].id] += 2;
            if(ph[mm[i].id] >= 2 && !vish[mm[i].id])
            {
                vish[mm[i].id] = true;
                printf("%s %d %d\n", home, mm[i].id, mm[i].time);
            }
        }
    }

    return 0;
}

   

B - Vasya and Wrestling

#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
using namespace std;
#define MAXN 200010
#define LL long long

int f[MAXN], s[MAXN], ftop, stop;
int tag, x;
LL score;

int cmp()
{
    int len = min(ftop, stop);
    for(int i = 0; i < len; i++)
    {
        if(f[i] > s[i])
            return 1;
        if(f[i] < s[i])
            return -1;
    }
    if(ftop > stop)
        return 1;
    if(ftop < stop)
        return -1;
    return 0;
}

int main()
{
//    freopen("B.in", "r", stdin);

    int n;
    scanf("%d", &n);
    score = 0;

    for(int i = 0; i < n; i++)
    {
        scanf("%d", &x);
        score += (LL)x;
        if(x > 0)
            f[ftop++] = x, tag = 0;
        else
            s[stop++] = -x, tag = 1;
    }
    if(score > 0)
        printf("first\n");
    else if(score < 0)
        printf("second\n");
    else
    {
        int flag = cmp();
        if(flag > 0)
            printf("first\n");
        else if(flag < 0)
            printf("second\n");
        else
        {
            if(tag == 0)
                printf("first\n");
            else
                printf("second\n");
        }
    }
    return 0;
}

C - Vasya and Basketball

#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
using namespace std;
#define MAXN 200010
#define INF 2*1e9
#define LL long long

LL a[MAXN], b[MAXN], d[2 * MAXN];
int n, m, dtop, atop, btop;
int x, ax, bx;

int main()
{
//    freopen("C.in", "r", stdin);
//    freopen("C.out", "w", stdout);

    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%I64d", a + i);
        a[i] *= 2;
        d[i] = a[i] - 1;
    }
    scanf("%d", &m);
    for(int i = 0; i < m; i++)
    {
        scanf("%I64d", b + i);
        b[i] *= 2;
        d[n + i] = b[i] - 1;
    }
    d[n + m] = INF;
    sort(a, a + n);
    sort(b, b + m);
    sort(d, d + n + m + 1);

    dtop = 0;
    for(LL i = 1; i <= n + m; i++)
        if(d[i] != d[dtop])
            d[++dtop] = d[i];

    x = atop = btop = ax = bx = 0;
    for(int i = 0; i <= dtop; i++)
    {
        while(a[atop] < d[i])
        {
            if(atop == n)
                break;
            atop++;
        }
        while(b[btop] < d[i])
        {
            if(btop == m)
                break;
            btop++;
        }
        if(btop - atop >= x)
        {
            x = btop - atop;
            if((ax > atop && (bx - ax == x)) || (bx - ax < x))
            {
                ax = atop;
                bx = btop;
            }
        }
    }
    printf("%d:%d\n", ax * 2 + (n - ax) * 3, bx * 2 + (m - bx) * 3);

    return 0;
}

D - Vasya and Chess

貌似cf上的题解已经讲了,代码很简单,但是不想去做了。。

抱歉!评论已关闭.