| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
打表都用了247MS...可能我的程序太水了……#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: |