Codeforces Round #575(Div.3) Problem-A & B & C

A. Three Piles of Candies

签到题

#include 
using namespace std;
typedef long long LL;

LL a[3];

int main()
{
    int q;
    scanf("%d", &q);
    while(q--)
    {
        scanf("%lld %lld %lld", &a[0], &a[1], &a[2]);
        sort(a, a+3);
        LL alice, bob;
        alice = a[0], bob = a[1];
        LL tmp = bob - alice;
        LL tmp2 = a[2] - tmp;
        alice += tmp2 / 2;
        bob += tmp2 / 2;
        alice += tmp;
        if(a[2] % 2 == 1)
            alice += 1;
        printf("%lld\n", min(alice, bob));

    }


    return 0;
}

 

B. Odd Sum Segments

打表记录从开始当前数字有多少个奇数。

注意:

偶数个数分为奇数个组不行
奇数个数分为偶数个组也不行
奇数个数小于k也不行

输出第1、2、3......k-1个奇数的下表,这是前k-1组,剩下的是第k组。

#include 
using namespace std;
const int N = 200010;

int a[N];
int b[N];
vector ve;

int main()
{
    int q;
    scanf("%d", &q);
    while(q--)
    {
        int n, k;
        scanf("%d %d", &n, &k);
        for(int i=1; i<=n; i++)
        {
            scanf("%d", &a[i]);
        }
        b[0] = 0;
        for(int i=1; i<=n; i++)     // 打表记录奇数个数
        {
            if(a[i]&1)  b[i] = b[i-1] + 1;
            else    b[i] = b[i-1];
        }
        if(b[n] % 2 ==0 && k%2 == 1)
            printf("NO\n");
        else if(b[n]%2 == 1 && k%2 == 0)
            printf("NO\n");
        else if(b[n] < k)
            printf("NO\n");
        else
        {
            printf("YES\n");
            int cnt = 1;
            for(int i=1; i<=n; i++)
            {
                
                if(cnt == k)
                    break;
                if(b[i] == cnt)
                {
                     printf("%d ", i);
                     cnt ++;
                }
                   
            }
            printf("%d\n", n);
        }
        

    }


    return 0;
}

 

C. Robot Breakout

根据条件缩小x和y的范围,最后输出x的最小值和y的最小值

#include 
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 100010;

struct node{
    int x, y;
    int left, up, right, down;
};
struct node a[N];

int main()
{
    int q;
    scanf("%d", &q);
    while(q--)
    {
        int n;
        scanf("%d", &n);
        for(int i=0; i minx)
                minx = a[i].x;
            if(a[i].right == 0 && a[i].x < maxx)
                maxx = a[i].x;
            if(a[i].up == 0 && a[i].y < maxy)
                maxy = a[i].y;
            if(a[i].down == 0 && a[i].y > miny)
                miny = a[i].y;            
        }
        if(minx > maxx || miny > maxy)
            printf("0\n");
        else
        {
            if(minx == -INF)
                minx = -100000;
            if(miny == -INF)
                miny = -100000;
            printf("1 %d %d\n", minx, miny);
            // if(maxx == INF)
            //     maxx = 100000;
            // if(maxy == INF)
            //     maxy == 100000;
            // printf("1 %d %d\n", maxx, maxy);
        }
        

    }


    return 0;
}

 

你可能感兴趣的:(codeforces)