标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 48916 | Accepted: 18476 |
Description
Input
Output
Sample Input
3 4 0
Sample Output
5 30
Source
1 /* 2 * Author: Joshua 3 * Created Time: 2015年01月31日 星期六 20时50分27秒 4 * File Name: poj1012.cpp 5 */ 6 #include<cstdio> 7 #include<iostream> 8 #include<cstring> 9 #define maxn 30 10 int k,f[maxn]; 11 12 void cal(int x) 13 { 14 int e[maxn],m=1,n=2*x; 15 bool flag; 16 e[0]=0; 17 while (1) 18 { 19 flag=true; 20 for (int i=1;i<=x;++i) 21 { 22 e[i]=(e[i-1]+m-1)%(n-i+1); 23 if (e[i]<x) 24 { 25 ++m; 26 flag=false; 27 break; 28 } 29 } 30 if (!flag) continue; 31 f[x]=m; 32 break; 33 } 34 } 35 36 int main() 37 { 38 memset(f,0,sizeof(f)); 39 while (scanf("%d",&k)&& k>0) 40 { 41 if (f[k]==0) cal(k); 42 printf("%d\n",f[k]); 43 } 44 return 0; 45 }
标签:
原文地址:http://www.cnblogs.com/code-painter/p/4266539.html