TopCoder SRM 152 div 2 500point

这个题目比较简单,自己在纸上写出来给的例子,然后分析一下就会发现规律了:)



我的代码

#include<vector>
#include<iostream>
using namespace std;
 
class LeaguePicks 
{
public:
    vector<int> returnPicks(int position, int friends, int picks);
 
};
 
vector <int> LeaguePicks::returnPicks(int position, int friends, int picks)
{
    vector <int> receive_picks;
    int a[] = {(friends - position) * 2 + 1, (position - 1) * 2 + 1};
 
    if (picks >= position) {
        receive_picks.push_back(position);
        int index = position;
        int i = 0;
        while(true) {
            index += a[i];
            if (index <= picks) {
                if (i == 0) i = 1;
                else i = 0;
                receive_picks.push_back(index);
            }
            else break;
        }
    }
 
    return receive_picks;
}
 
void main()
{
    LeaguePicks test;
    vector <int> result = test.returnPicks(3, 6, 15);
    for(int i = 0; i < result.size(); i++) {
        cout<<result.at(i)<<" ";
    }
    cout<<endl;
    result = test.returnPicks(1, 1, 10);
    for(int i = 0; i < result.size(); i++) {
        cout<<result.at(i)<<" ";
    }
    cout<<endl;
    result = test.returnPicks(1, 2, 39);
    for(int i = 0; i < result.size(); i++) {
        cout<<result.at(i)<<" ";
    }
    cout<<endl;
    result = test.returnPicks(5, 11, 100);
    for(int i = 0; i < result.size(); i++) {
        cout<<result.at(i)<<" ";
    }
    cout<<endl;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值