Under my umbrella.

SKII

Less is more.

蓝桥杯 2013年 第四届 JAVA B组 题解

蓝桥杯 2013年 第四届 JAVA B组 题解

One

package provincial_2013B;
/**
 * my answer: 2299
 */
import java.util.Calendar;

public class One {
	public static void main(String[] args) {
		Calendar calendar = Calendar.getInstance();
		for(int i = 1999; i < 10000; i += 100) {
			calendar.set(Calendar.YEAR, i);
			calendar.set(Calendar.MONTH, 11);
			calendar.set(Calendar.DAY_OF_MONTH, 31);
			if(calendar.get(Calendar.DAY_OF_WEEK) == 1) {
				System.out.println(calendar.get(Calendar.YEAR));
				break;
			}
		}
	}
}

Two

package provincial_2013B;
/**
 * my answer: 142
 *
 */
public class Two {
	public static void main(String[] args) {
		int cnt = 0;
		for(int i = 1; i < 10; i++) {
			for(int j = 1; j < 10; j++) {
				if(i != j)
				for(int k = 1; k < 10; k++) {
					if(i != k && j != k)
					for(int l = 1; l < 10; l++) {
						if(i!=l&&j!=l&&k!=l)
						for(int m = 1; m < 10; m++) {
							if(i!=m&&j!=m&&k!=m&&l!=m)
							if((i*10+j)*(k*100+l*10+m) ==
								(i*100+l*10+j)*(k*10+m)) {
								cnt ++;
							}
						}
					}
				}
			}
		}
		System.out.println(cnt);
	}
}

Three

package provincial_2013B;
/**
 * my answer: 35
 * @author AoMok
 *
 */
public class Three {
	public static int dfs(int x, int y) {
		if(x == 4 || y == 3) {
			return 1;
		}
		
		return dfs(x+1, y) + dfs(x, y+1);
	}
	public static void main(String[] args) {
		System.out.println(dfs(0, 0));
	}
}

Four

package provincial_2013B;
/**
 * my answer: 0.6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911375
 * 
 */
import java.math.BigDecimal;

public class Four {
	public static void main(String[] args) {
		BigDecimal a = BigDecimal.ONE;
		BigDecimal b = BigDecimal.ONE;
		for(int i = 0; i < 10000; i++) {
			BigDecimal t = b;
			b = b.add(a);
			a = t;
//			System.out.println(a + " " + b);
		}
//		System.out.println(a + "\n" + b);
		System.out.println(a.divide(b, 101, BigDecimal.ROUND_HALF_UP));
	}
}

Five

// 太简单,不写

Six

package provincial_2013B;

public class Six {
	public static void threeDepartmentSort(int[] a) {
		int p = 0, left = 0, right = a.length - 1;
		int standard = a[left];
		while(p <= right){
			standard = a[left];
			if(a[p] < standard) {
				int t = a[p];
				a[p] = a[left];
				a[left] = t;
				
				left++;
			} else if(a[p] > standard) {
				int t = a[p];
				a[p] = a[right];
				a[right] = t;
				
				right--;
			} else {
				p++;
			}
		}
	}
	
	public static void main(String[] args) {
		int[] a = {25,18,-2,0,16,-5,33,21,0,19,-16,25,-3,0};
		threeDepartmentSort(a);
		for(int e: a)
			System.out.print(e+" ");
	}
}

Seven

package provincial_2013B;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Seven {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		scanner.nextLine();
		ArrayList<Integer> aList = new ArrayList<Integer>();
		for(int i = 0; i < n; i++) {
			String[] li = scanner.nextLine().split(" ");
			for(int j = 0; j < li.length; j++) {
				aList.add(Integer.parseInt(li[j]));
			}
		}
		Collections.sort(aList);
		int indexOfDis = 0, indexOfRep = 0;
		for(int i = 1; i < aList.size(); i++) {
			if(aList.get(i).equals(aList.get(i-1))) {
				indexOfRep = i;
			} else if(aList.get(i) - aList.get(i-1) == 2) {
				indexOfDis = i;
			}
		}
		int first = aList.get(0);
		System.out.println((indexOfDis+first) + " " + (indexOfRep+first));
		
//		for(int i = 0; i < aList.size(); i++) {
//			System.out.print(aList.get(i) + " ");
//		}
	}
}

Eight

package provincial_2013B;
/**
 * TMD阅读理解杯,懒得写了
 */

Nine

package provincial_2013B;

import java.util.Scanner;

public class Nine {
	private static int cnt = 0;
	private static int N;
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		N = scan.nextInt();
		
		int[] a = {1,2,3,4,5,6,7,8,9};
		permutation(a, 0);
		
		System.out.println(cnt);
	}
	public static int arrToNum(int[] a, int begin, int end) {
		int ans = 0;
		for(int i = begin; i<= end; i++) {
			// ten power: (end-start+1)-(i-start+1)=end-i
			ans += a[i]*Math.pow(10, end-i);
		}
		return ans;
	}
	
	public static void check(int[] a) {
		for(int i = 1; i < a.length-2; i++) {
			int num1 = arrToNum(a, 0, i-1);
			// 剪枝优化
			if(num1>=N) continue;
			for(int j = 2; j < a.length-1; j++) {
				int num2 = arrToNum(a, i, j-1);
				int num3 = arrToNum(a, j, a.length-1);
				if(num2%num3==0 && num1+num2/num3==N) {
					cnt++;
				}
			}
		}
	}
	
	public static void print(int[] a) {
		for(int i = 0; i < a.length; i++) {
			System.out.print(a[i]);
			if(i+1!=a.length) System.out.print(" ");
		}
		System.out.println();
	}
	
	public static void permutation(int[] a, int k) {
		if(k >= a.length) {
			check(a);
			return;
		}
		for(int i = k; i < a.length; i++) {
			int t = a[k];
			a[k] = a[i];
			a[i]= t;
			
			permutation(a, k+1);
			
			t = a[k];
			a[k] = a[i];
			a[i]= t;
		}
	}
}

Ten

package provincial_2013B;

import java.util.Scanner;

public class Ten {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++) arr[i] = scan.nextInt();
		
		int cnt = 0;
		for(int i = 0; i < n; i++) {
			int max = arr[i];
			int min = arr[i];
			for(int j = i; j < n; j++) {
				if(max<arr[j]) max = arr[j];
				if(min>arr[j]) min = arr[j];
				if(max-min+1==j-i+1) {
					cnt++;
				}
			}
		}
		System.out.println(cnt);
	}
}

posted @ 2020-03-03 18:27  NLYang  阅读(242)  评论(0编辑  收藏  举报