02TopcoderSRM710B

Problem Statement

    

Mancala is a family of games that are played using tokens (such as seeds or pebbles) that are placed into holes or pits in the ground. In this problem we will call the tokens "stones" and the holes "slots".

You are playing a variant of mancala with n slots around a circle. The slots are labeled from 0 to n-1 in clockwise order. Initially, each slot may contain some stones: for each i, slot i contains start[i] stones.

The game is played in turns. In each turn you do the following:

  1. You choose a non-empty slot and you take all stones from that slot into your hand.
  2. While you have some stones in your hand, you repeat the following process: you move one slot clockwise and you drop one stone into that slot.

Note that if you picked up a lot of stones you may go around the whole circle multiple times. Also note that during the second step you also place stones into the slot chosen in the first step. For example, suppose we have four slots with the following numbers of stones: (6, 3, 4, 0). Next, suppose that in step 1 we chose slot 0, i.e., the slot that contains 6 stones. In step 2 we will place those 6 stones into slots 1, 2, 3, 0, 1, and 2. After this turn the stones will be distributed as follows: (1, 5, 6, 1).

You are given the vector <int> start with n elements: the initial distribution of the stones. Find and return any sequence of at most 2500 moves that leads to a state in which all stones are in a single slot. For the constraints used in this problem it is guaranteed that such a sequence of moves exists. Note that you do not need to minimize the number of moves, any valid sequence will be accepted.

In order to return a sequence that consists of x moves, return a vector <int> with x elements: for each turn in chronological order, the number of the slot you chose.

Definition

    
Class:ForwardMancala
Method:findMoves
Parameters:vector <int>
Returns:vector <int>
Method signature:vector <int> findMoves(vector <int> start)
(be sure your method is public)

Limits

    
Time limit (s):2.000
Memory limit (MB):256
Stack limit (MB):256

Constraints

-start will contain between 2 and 10 elements, inclusive.
-Each element of start will be between 0 and 10, inclusive.
-It is guaranteed that the sum of elements in start is positive.

Examples

0) 
    
{6,1,0,1}
Returns: {1, 2, 3, 1, 2, 3 }
In this case, the states would look as follows:
  • (6,1,0,1)
  • (6,0,1,1)
  • (6,0,0,2)
  • (7,1,0,0)
  • (7,0,1,0)
  • (7,0,0,1)
  • (8,0,0,0)
1) 
    
{0,10,0,0,0}
Returns: { }
In this case, all the stones are already in one slot, so we don't have to do anything.
2) 
    
{0,1,0,1,0,1}
Returns: {3, 4, 1, 2, 3, 4 }
 
3) 
    
{5,0,0,1,3,0,2,0}
Returns: {3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7 }
 
4) 
    
{10,10,10,10,10,10,10,10,10,10}
Returns: 
{1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5,
 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2,
 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8,
 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5,
 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
 

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

#include <vector>
using namespace std;
class ForwardMancala{
public :
    vector<int>findMoves(vector<int>start)
    {
        vector<int>ret;
        while(1){
                 int index=-1,count=0;
        for(int i=0;i<start.size();i++){
            if(start[i]!=0){
                count++;
                index=i;
            }
        }
        if(count==1)return ret;
        ret.push_back(index);
        int selected=start[index];
        start[index]=0;
        
        for(int i=1;i<=selected;i++)
        {
            start[(index+i)%start.size()]++;
        }
        
        }
        return ret;
    }
     };

  

转载于:https://www.cnblogs.com/passion-sky/p/8561732.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值