各题分值:
1.世纪末的星期(结果填空) 3分
2.马虎的算式(结果填空) 6分
3.振兴中华 ( 结果填空) 8分
4.黄金连分数( 结果填空) 13分
5.有理数类( 代码填空) 5分
6.三部排序 (代码填空) 8分
7.错误票据( 编程大题) 5分
8.幸运数(编程大题) 10分
9.带分数(编程大题) 15分
10.连号区间数(编程大题) 27分
第一题
题目:世纪末的星期
曾有邪教称1999年12月31日是世界末日。当然该谣言已经不攻自破。
还有人称今后的某个世纪末的12月31日,如果是星期一则会...
有趣的是,任何一个世纪末的年份的12月31日都不可能是星期一!!
于是,“谣言制造商”又修改为星期日......
1999年的12月31日是星期五,请问:未来哪一个离我们最近的一个世纪末年(即xx99年)的
12月31日正好是星期天(即星期日)?
请回答该年份(只写这个4位整数,不要写12月31等多余信息)
思路:%7后差两天就是星期日,加5 %70或者%72都行
public class Main {
public static void main(String[] args)
{
int year = 2000;
int total = 0;
for( ; ; year++) {
if(year%400==0 || (year%4==0 && year%100!=0)){
//闰年
total += 366;
}else {
total += 365;
}
if((total+5)%7 == 0 && (year+"").endsWith("99")){
//判断year是否以99结尾,
System.out.println(year);
break;
}
}
}
}
第二题
题目:马虎的算式
小明是一个急性子,上小学的时候经常把老师写在黑板上的题目抄错。
有一次,老师出得题目是:36*495=? 他却给抄成了:396*45=?
但结果却很戏剧性,他的答案竟然是对的!!
因为36*495=396*45=17820
类似这样的巧合情况可能还有很多,
比如:27*594=297*54
假设a b c d e代表1-9不同的5个数字(注意是各不相同的数字,且不含0)
能满足形如:ab*cde=adb*ce这样的算式一共有多少种呢?
1.直接枚举暴力
public class Main {
static int ans = 0;
public static void main(String[] args) {
int cnt = 0;
for (int a = 1; a < 10; a++) {
for (int b = 1; b < 10; b++) {
if (b != a) {
for (int c = 1; c < 10; c++) {
if (c != b && c != a) {
for (int d = 1; d < 10; d++) {
if (d != c && d != b && d != a) {
for (int e = 1; e < 10; e++) {
if (e != d && e != c && e != b && e != a) {
int t1 = a * 10 + b;
int t2 = c * 100 + d * 10 + e;
int t3 = a * 100 + d * 10 + b;
int t4 = c * 10 + e;
if (t1 * t2 == t3 * t4)
cnt++;
}
}
}
}
}
}
}
}
}
System.out.println(cnt);
}
}
2.dfs搜索
public class Main {
static int ans = 0;
static boolean[] vis = new boolean[10];
static int[] num = new int[6];
static void dfs(int pos) {
if (pos == 6) {
int t1 = num[1] * 10 + num[2];
int t2 = num[3] * 100 +