#我爱cf之每日一题——模拟就怕懒 03

Codeforces Round #478 (Div. 2)

B.Mancala

思路:其实这就是个模拟题,但是得分清楚。总共有14个坑的话,超过14归于0,那么应该使用mod函数。除此之外的是循环问题,一层循环相当于n-14,循环了几层其他数就相当于加了几,因此加的数字相当于n/14。

代码:

#include<iostream>
#include<cstdio>
using namespace std;

int main(){
    int a[14];
    for(int i = 0; i < 14; i++)
        cin>>a[i];
    long long res = 0;
    int t[14];
    for(int i = 0; i < 14; i++)
    {
        for(int j = 0; j < 14; j++)
            t[j] = a[j];
        long long tmp = t[i];
        t[i] = 0;
        for(int j = 0; j < 14; j++)
            t[j] += tmp / 14;
        tmp %= 14;
        int k = i + 1;
        while(tmp--)
        {
            if(k == 14)
                k = 0;
            t[k]++;
            k++;
        }
        long long score = 0;
        //接下来求偶数的总和
        for(int j = 0; j < 14; j++)
        {
            if(t[j] & 1)
                continue;
            score += t[j];
        }
        res = max(res, score);
    }
    cout << res << endl;
	return 0;
}

在求偶数的和这一部分中,其实是有技巧的:

long long score = 0;
        //接下来求偶数的总和
        for(int j = 0; j < 14; j++)
        {
            if(t[j] & 1)
                continue;
            score += t[j];
        }
通过位运算来提高效率,很不错的方法。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值