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

打表都用了247MS...可能我的程序太水了……

Posted by wuxiangyu at 2012-01-18 13:55:18 on Problem 1012
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;

bool check(int k, int m){
    int n=k*2, p=0;
    for (int i=0; i<k; i++){
        p = (p+m)%n;
        if (p < k) return false;
        n--;
    }
    return true;
}

int solve(int k)
{
    int ret = k+1;
    while (!check(k, ret-1)) ret++;
    return ret;
}

int table[14];

int main()
{
    for (int i=0; i<14; i++)
        table[i] = solve(i);
        
    int k;
    while (cin>>k, k){
        cout<<table[k]<<endl;
    }
    
    //system("pause");
    return 0;
}

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