CodeForces - 975B:Mancala(暴力)

39 篇文章 1 订阅
4 篇文章 0 订阅

链接https://vjudge.net/problem/CodeForces-975B

题目
Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes.
在这里插入图片描述
Initially, each hole has ai stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next holes in a counter-clockwise direction.

Note that the counter-clockwise order means if the player takes the stones from hole i, he will put one stone in the (i+1)-th hole, then in the (i+2)-th, etc. If he puts a stone in the 14-th hole, the next one will be put in the first hole.

After the move, the player collects all the stones from holes that contain even number of stones. The number of stones collected by player is the score, according to Resli.

Resli is a famous Mancala player. He wants to know the maximum score he can obtain after one move.

题意
一共有14个盘子,每个盘子里有a[i]个石头(a[i]要么为0,要么为奇数)。
现在你可以任意选择一个盘子,然后把盘子里的石头分发给后面的盘子,每次发一个。
如果发完第14个盘子之后还有石头,则从第一个继续发,直到石头没了。
你最终的报酬是所有有偶数个石头的盘子里所有的石头。问你最多能拿到多少石头?

思路
既然n只有14,我们就暴力一手。把每个盘子都搞一遍,看哪个报酬最多就用哪个方案。

看代码,伊丽莎白!

在这里插入图片描述
代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[15],b[15];
int main()
{
    while(~scanf("%lld",&a[1]))
    {
        ll cnt=0;
        for(int i=2;i<=14;i++)
            scanf("%lld",&a[i]);
        for(int i=1;i<=14;i++)
        {
            ll sum=0;
            ll ans=a[i];
            if(ans==0)  //当前盘子里没有石头
                continue;
            for(int j=1;j<=14;j++)
                b[j]=a[j];
            b[i]=0;
            int t=ans/14;
            for(int j=1;j<=14;j++)
                b[j]+=t;
            ans%=14;
            int pos=i+1;
            while(ans)
            {
                if(pos==15)
                    pos=1;
                b[pos]++;
                ans--;
                pos++;
            }                   //分发石头的过程,这部分是关键
            for(int j=1;j<=14;j++)
            {
                if(b[j]%2==0)
                    sum+=b[j];
            }
            cnt=max(sum,cnt);
        }
        cout<<cnt<<endl;
    }
}

穷,限制了我的想象力。

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值