POJ1012
来源:互联网 发布:http aq.qq.com js 编辑:程序博客网 时间:2024/05/19 20:46
import java.util.Scanner;
public class Main
{
static int k;
static int bnum;
static int m;
static int[] resu=new int[14];
public static void main(String[] args) throws FileNotFoundException{ Scanner sc=new Scanner(System.in); sc=new Scanner(new File("/storage/emulated/0/AppProjects/Test/src/joseph")); while(true){ k=sc.nextInt(); if(k==0) break; if(resu[k]!=0){ System.out.println(resu[k]); continue; } boolean is=true; for(int i=k+k/2+1;i>1;i++){ if(i%(2*k)>=1&&i%(2*k)<=k) continue; bnum=k; m=i; is=isSafe(2*k,1,k); if(is){ resu[k]=i; System.out.println(i); break; } } }}private static boolean isSafe(int n,int s,int t){ if(bnum==0) return true; int res=m%n; if(res==0) res=n; if(res>=s&&res<=t) return false; bnum--; return isSafe(n-1,(n-res+s)%n,(n-res+s)%n+k-1);}
}
sample input:
1
2
3
4
5
6
7
8
9
10
11
12
13
0
sample output:
2
7
5
30
169
441
1872
7632
1740
93313
459901
1358657
2504881
0 0
- POJ1012
- POJ1012
- POJ1012
- poj1012
- poj1012
- poj1012
- poj1012
- poj1012
- poj1012
- POJ1012
- poj1012
- poj1012 约瑟夫
- 枚举 poj1012
- POJ1012 Joseph
- poj1012 Joseph
- POJ1012 Joseph
- poj1012-Joseph
- poj1012 joseph
- 索引负面影响测试
- 安鑫 对不起,我们必须辞退你
- ios自学经验
- 关于报错:Attempt to invoke virtual method 'int Android.view.View.getImportantForAccessibility()'
- android framework添加系统服务
- POJ1012
- VIVO手机上del键无效OnKeyListener不响应问题
- 叶俊:从一匹马的电影读懂人才管理与商业经营
- cocoapods安装pod setup error解决方法
- Hive学习笔记 --- Array, Map, Struct类型使用
- Apache之——多虚拟主机多站点配置的两种实现方案
- ArcGIS API For Javascript之调用动态地图服务+属性、空间查询
- MySQL 设置数据表编码
- 抓取系统log