1.诸葛亮的排列组合
看成正方形的四个角,旋转三次,直接暴力枚举四种状态,一一对应
import java.util.Scanner; public class A1 { public static void main(String[] args) { int a[][]=new int [5][5]; int b[][]=new int [5][5]; Scanner sc=new Scanner(System.in); int t,k=1; t=sc.nextInt(); while(k<=t){ for (int k2 = 1; k2 <= 2; k2++) { for (int l = 1; l <=2; l++) { a[k2][l]=sc.nextInt(); } } for (int k2 = 1; k2 <= 2; k2++) { for (int l = 1; l <=2; l++) { b[k2][l]=sc.nextInt(); } } int flag=0; if(a[1][1]==b[1][1]&&a[1][2]==b[1][2]&&a[2][1]==b[2][1]&&a[2][2]==b[2][2])flag=1; else if(a[1][1]==b[1][2]&&a[1][2]==b[2][2]&&a[2][1]==b[1][1]&&a[2][2]==b[2][1])flag=1; else if(a[1][1]==b[2][2]&&a[1][2]==b[2][1]&&a[2][1]==b[1][2]&&a[2][2]==b[1][1])flag=1; else if(a[1][1]==b[2][1]&&a[1][2]==b[1][1]&&a[2][1]==b[2][2]&&a[2][2]==b[1][2])flag=1; if(flag==1){ System.out.println("Case #"+k+": "+"POSSIBLE"); } else{ System.out.println("Case #"+k+": "+"IMPOSSIBLE"); } k++; } } }
2.华佗的药瓶,水题
import java.util.Scanner; public class B { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); int k=0; while(++k<=t) { int n=sc.nextInt(); int m=2*n-1; System.out.println("Case #"+k+": "+m); } } }
3.水题
两个数组的对照,下标找对就行了
import java.util.Scanner; public class C { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); int k=0; while(++k<=t) { int n=sc.nextInt(); int m=sc.nextInt(); int p=sc.nextInt(); int a[]=new int [n]; int b[]=new int [m]; for (int i = 0; i < a.length; i++) a[i]=sc.nextInt(); for (int i = 0; i < b.length; i++) b[i]=sc.nextInt(); int q=n-(m-1)*p; int s1=0; for (int i = 0; i < q; i++) { int num=0; for (int j = 0; j < b.length ; j++) { //是否对应 if(b[j]==a[i+j*p] && i+j*p<a.length) num++; } //如果全部对应 if(num==b.length) {s1++;} } System.out.println("Case #"+k+": "+s1); } } }