import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static int kase=0,n;
public static int [] circles=new int [50];
public static boolean[] flag=new boolean[50],primes=new boolean[50];
public static void intiPrimes()
{Arrays.fill(primes,true);
for(int i=2;i<=30;i++)
{
for(int j=i+i;j<50;j+=i)
{
if(j%i==0)
primes[j]=false;
}
}
primes[0]=primes[1]=false;

}
public static void DFS(int i)
{if(i==n)
{if(primes[1+circles[n-1]]){
for(int j=0;j<n;j++)
{if(j==n-1)
System.out.print(circles[j]);
else
System.out.print(circles[j]+" ");

}
System.out.println();
}
return;
}
else
{for(int j=2;j<=n;j++)
{if(flag[j]){
if(primes[j+circles[i-1]]&&(j+circles[i-1]&1)!=0)
{
flag[j]=false;
circles[i]=j;
DFS(i+1);
flag[j]=true;
}
}
}
}
return;
}
public static void main(String[] args)
{Scanner in=new Scanner(System.in);
intiPrimes();
while(in.hasNext())
{n=in.nextInt();
System.out.println("Case"+" "+(++kase)+":");
if(n==1)
{System.out.println(1);
System.out.println();
continue;
}
else if((n&1)!=0)
{System.out.println();
continue;
}
Arrays.fill(flag,true);
circles[0]=1;
flag[1]=false;
DFS(1);
System.out.println();
}
}
}

System.out.println("Case"+" "+(++kase)+":");注意这个地方的输出方式;

hdu1016JAVA的更多相关文章

随机推荐

  1. 【CF】328 D. Super M

    这种图论题已经变得简单了... /* D */ #include <iostream> #include <string> #include <map> #incl ...

  2. git获取远端版本库上的Tag (没有clone[远端的版本库太大了])

    方法一 http://stackoverflow.com/questions/25815202/git-fetch-a-single-commit The git fetch command deli ...

  3. trash目录: ~/.local/share/Trash

    trash目录:~/.local/share/Trash

  4. Reflector+Reflexil 相结合实现对DLL文件修改

    在工作过程中,我们有可能遇到这样的问题:公司发给客户的软件包突然报错了,但是你知道哪里报错了,而这个代码已经编译成DLL文件了,源代码不在自己这里.怎么办呢?还好现在有Reflexil插件,这个插件只 ...

  5. CodeForces 400

    A - Inna and Choose Options Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d &a ...

  6. SQL Server 2008 数据库日志文件丢失处理方法

    当数据库发生这种操作故障时,可以按如下操作步骤可解决此方法,打开数据库里的Sql 查询编辑器窗口,运行以下的命令. 1.修改数据库为紧急模式 ALTER DATABASE Zhangxing SET ...

  7. App性能优化

    http://www.cocoachina.com/ios/20150429/11712.html http://blog.csdn.net/jasonblog/article/details/765 ...

  8. LightOJ 1245 Harmonic Number (II) 水题

    分析:一段区间的整数除法得到的结果肯定是相等的,然后找就行了,每次是循环一段区间,暴力 #include <cstdio> #include <iostream> #inclu ...

  9. 如何在GeoServer上发布一张地图

    在GeoServer上发布一张地图步骤大致如下: 先准备一张地图,格式可以是:jpg.png.tif等. Jpg文件对应的坐标信息文件为jgw格式文件,投影文件为prj文件;Tif文件对应的坐标信息文 ...

  10. Windows Azure公有云服务相关方案

    http://www.cnblogs.com/sennly/p/4139675.html 1.公有云平台服务简介 Windows Azure 是一个灵活而开放的云平台,通过该平台,您可以在数据中心快速 ...