Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

去年打了个表,今年A了这道题

Posted by 134115080060 at 2015-01-17 10:36:33 on Problem 1012
#include<iostream>
using namespace std;

#define maxn 40

int JosePh(int k, int m)
{
    int i=0, a[maxn]={0}, n=2*k, T=k;

    while(T--)
    {
        int j=0;

        int t = (m+k+T+1)%(k+T+1);

        while(j<=t)
        {
            if(i == n)i=0;
            if(a[++i] == 0)
                j++;
        }

        if(i <= k)
            return 0;
        a[i] = 1;
    }

    return 1;
}

int main()
{
    int i, k, a[maxn]={0};

    for(k=1; k<14; k++)
    {
     for(i=1; ; i++)
        {
            if(JosePh(k, i) == 1)
                break;
        }
    a[k] = i+1;
    }
    while(cin >> k, k)
    {
        cout << a[k] << endl;
    }

    return 0;
}


//93313

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator