[Codeforces] Round #292 (Div. 2) A、B、C

515 A - Drazil and Date

输入一个坐标(a, b), 接着输入一个整数s.
问:从(0, 0)能否正好s步走到坐标(a, b)?
思考后可以发现,两点之间的最少步数等于横坐标的差+纵坐标的差。
想要凑出s,必然每次要增加偶数步。

#include <stdio.h>
using namespace std;
int abs(int x)
{
    if(x < 0) return -x;
    return x;
}
int main()
{
    long long a, b, s;
    while(~scanf("%I64d %I64d %I64d", &a, &b, &s))
    {
        int ans = abs(a) + abs(b);
        if((ans + s) % 2 == 0 && s >= ans)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
    }
    return 0;
}

515 B - Drazil and His Happy Friends

第一行输入两个整数n、m分别代表男、女的人数。
第二行首先输入一个整数b, 接下来跟b个整数。分别代表xi个男生是快乐的。
第三行首先输入一个整数g, 接下来跟g个整数。分别代表第yi个女生是快乐的。
现规定男、女生每天按顺序循环搭配,每天中的一个男生和一个女生至少有一个是开心的,能使当天不开心的人变开心。否则每个人的不变。
问:经过无数天后,是否能使所有人都开心,如果能输出”Yes”,否则输出”No”。
由于n, m范围比较小,最少需要n*m天才能完成所有男生与女生的搭配。由于搭配的过程中,有些人的心情是可能变化过的。所以遍历两次即可。也就是n*m*2。最后判断一下每个男生和女生是不是至少有一个开心。

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main()
{
    int n, m, b, g, tmp;
    int f1[1000], f2[1000], i;
    while(~scanf("%d %d", &n, &m))
    {
        memset(f1, 0, sizeof(f1));
        memset(f2, 0, sizeof(f2));
        scanf("%d", &b);
        for(i = 0; i < b; i++)
        {
            scanf("%d", &tmp);
            f1[tmp] = 1;
        }
        scanf("%d", &g);
        for(i = 0; i < g; i++)
        {
            scanf("%d", &tmp);
            f2[tmp] = 1;
        }
        for(i = 0; i < n*m*2; i++)
        {
            if(f1[i%n] + f2[i%m] >= 1)
            {
                f1[i%n] = f2[i%m] = 1;
            }
        }
        int flag = 1;
        for(i = 0; i < max(n, m); i++)
        {
            if(f1[i] + f2[i] == 0)
            {
                flag = 0;
                break;
            }
        }
        if(flag) puts("Yes");
        else puts("No");
    }
    return 0;
}

515 C - Drazil and Factorial

题目的意思就是找一个数字与数字a的每个位的阶乘的乘积相等的最大数。
让数字尽量大,那也就是让数字的位数尽量多。
莫非就是把输入的数字a等价化成另一种形式。
通过思考后发现:
4! = 2! * 2!
6! = 5! * 3!
8! = 2! * 2! *2!
9! = 7! * 3! * 3! * 2!(可惜比赛的时候这个情况没有考虑到,被Hack了 - -)
其他的数字不能进行转化。
把转化后的每位数字按递减顺序输出即可。

#include <stdio.h>
#include <string.h>
#include <map>
#include <algorithm>
using namespace std;
int ans[100];
int gao(int k)
{
    if(k == 4)
    {
        ++ans[3];
        ans[2] += 2;
    }
    else if(k == 6)
    {
        ++ans[5];
        ++ans[3];
    }
    else if(k == 8)
    {
        ans[2] += 3;
        ++ans[7];
    }
    else if(k == 9)
    {
        ++ans[7];
        ans[3] += 2;
        ++ans[2];
    }
    else
    {
        ++ans[k];
    }
}
int main()
{
    int n;
    char ch[100];
    while(~scanf("%d", &n))
    {
        memset(ans, 0, sizeof(ans));
        scanf("%s", ch);
        for(int i = 0; i < n; i++)
        {
            if(ch[i] > '1')
            {
                gao(ch[i] - '0');
            }
        }
        for(int i = 9; i >= 2; i--)
        {
            for(int j = 0; j < ans[i]; j++)
            {
                printf("%d", i);
            }
        }
        puts("");
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值