1.題目標題:高斯日記
大數學家高斯有個好習慣:無論如何都要記日記。
他的日記有個與衆不同的地方,他從不註明年月日,而是用一個整數代替,比如:4210
後來人們知道,那個整數就是日期,它表示那一天是高斯出生後的第幾天。這或許也是個好習慣,它時時刻刻提醒着主人:日子又過去一天,還有多少時光可以用於浪費呢?
高斯出生於:1777年4月30日。
在高斯發現的一個重要定理的日記上標註着:5343,因此可算出那天是:1791年12月15日。
高斯獲得博士學位的那天日記上標着:8113
請你算出高斯獲得博士學位的年月日。
提交答案的格式是:yyyy-mm-dd, 例如:1980-03-21
請嚴格按照格式,通過瀏覽器提交答案。
注意:只提交這個日期,不要寫其它附加內容,比如:說明性的文字。
分析:這實際就是“三天打魚、兩天曬網問題”。
程序實現:(java寫的)
- package Forth;
- public class DateOfNdays {
- /*
- * 高斯日記(給定日期,算出X天后的日期)
- */
- /*
- * 是否是閏年
- */
- boolean IsleapYear(int year){
- return (year % 400 == 0 || year % 4 == 0 && year % 100 != 0);
- }
- /*
- * 獲得某年某月的最大天數
- */
- int GetMaxDay(int year,int month,int day){
- switch(month){
- case 1:
- case 3:
- case 5:
- case 7:
- case 8:
- case 10:
- case 12:
- return 31;
- case 4:
- case 6:
- case 9:
- case 11:
- return 30;
- case 2:
- return (IsleapYear(year)?29:28);
- default:
- return -1;
- }
- }
- /*
- * 獲得X天后的日期
- */
- void GetXDays(int year,int month,int day,int X){
- for(int i = 1; i <= X; i++){
- if(day != GetMaxDay(year,month,day)){
- day++;
- }else{
- if(month != 12){
- month++;
- day = 1;
- }else{
- month = day = 1;
- year++;
- }
- }
- }
- System.out.println(X+"天后的日期是"+year+"/"+month+"/"+day);
- }
- }
答案:1799-7-16
2.題目標題: 排它平方數
小明正看着 203879 這個數字發呆。
原來,203879 * 203879 = 41566646641
這有什麼神奇呢?仔細觀察,203879 是個6位數,並且它的每個數位上的數字都是不同的,並且它平方後的所有數位上都不出現組成它自身的數字。
具有這樣特點的6位數還有一個,請你找出它!
再歸納一下篩選要求:
1. 6位正整數
2. 每個數位上的數字不同
3. 其平方數的每個數位不含原數字的任何組成數位
答案是一個6位的正整數。
請通過瀏覽器提交答案。
注意:只提交另一6位數,題中已經給出的這個不要提交。
注意:不要書寫其它的內容(比如:說明性的文字)。
- package Forth;
- public class ExcludeNumber {
- /*
- * 排它平方數
- */
- long PingNum = 0; //存儲平方
- /*
- * 判斷一個數是否有重複數字
- */
- public boolean IsSame(long x){
- long store[] = new long[7];
- long r;
- int i = 0;
- while(x != 0){ //分離該數的每一位,存入store數組
- r = x % 10;
- x = x / 10;
- store[i] = r;
- i++;
- }
- long result;
- for(int j = 0; j < 5; j++){ //判斷有無重複數
- result = store[j];
- for(int k = j+1; k < 6; k++){
- if(result == store[k])
- return true;
- }
- }
- return false;
- }
- public boolean IsSame2(long Num,long n){
- long store[] = new long[7];
- long r;
- int i = 0;
- while( n != 0){
- r = n % 10;
- n = n / 10;
- store[i] = r;
- i++;
- }
- long storeping[] = new long[18];
- i = 0;
- while(Num != 0){
- r = Num % 10;
- Num = Num / 10;
- storeping[i] = r;
- i++;
- }
- for(int k = 0; k < 6; k++){ //將該數的每一位與其平方的每一位比較,看是否有相同的數
- for(int j = 0; j < i; j++){
- if(store[k] == storeping[j])
- return true;
- }
- }
- return false;
- }
- public void selectNum(){ //篩選排他數
- for(long n = 100000; n <= 999999;n++){
- if(IsSame(n)) //有相同的數字,則跳過
- continue;
- else{
- PingNum = n*n;
- if(IsSame2(PingNum,n)) //該數的平方中是否有與該數相同的數字
- continue;
- else //符合條件,則打印
- System.out.println(n);
- }
- }
- }
- }
答案:639172
3.標題: 振興中華
小明參加了學校的趣味運動會,其中的一個項目是:跳格子。
地上畫着一些格子,每個格子裏寫一個字,如下所示:(也可參見p1.jpg)
從我做起振
我做起振興
做起振興中
起振興中華
比賽時,先站在左上角的寫着“從”字的格子裏,可以橫向或縱向跳到相鄰的格子裏,但不能跳到對角的格子或其它位置。一直要跳到“華”字結束。
要求跳過的路線剛好構成“從我做起振興中華”這句話。
請你幫助小明算一算他一共有多少種可能的跳躍路線呢?
答案是一個整數,請通過瀏覽器直接提交該數字。
注意:不要提交解答過程,或其它輔助說明類的內容。
- /*
- * 振興中華
- */
- int array[][] =
- {{0,1,2,3,4},
- {1,2,3,4,5},
- {2,3,4,5,6},
- {3,4,5,6,7}};
- int copyarray[][] = new int[4][5]; //顯示路徑的拷貝數組
- int startI = 0, startJ = 0; // 入口
- int endI = 3, endJ = 4; // 出口
- int success = 0;
- int count = 0;
- /*
- * 初始化拷貝數組
- */
- public void initcopy(){
- for(int k = 0; k < 4; k++){
- for(int d = 0; d < 5; d++){
- copyarray[k][d] = 10;
- }
- }
- }
- /*
- * 遍歷訪問
- */
- public void visit(int i,int j){
- copyarray[i][j] = array[i][j];
- if(i == endI && j == endJ){
- count++;
- System.out.print("\n 顯示路徑:\n");
- for(int k = 0; k < 4; k++){
- for(int d = 0; d < 5; d++){
- if(copyarray[k][d] == 0)
- System.out.print("從");
- else if(copyarray[k][d] == 1)
- System.out.print("我");
- else if(copyarray[k][d] == 2)
- System.out.print("做");
- else if(copyarray[k][d] == 3)
- System.out.print("起");
- else if(copyarray[k][d] == 4)
- System.out.print("振");
- else if(copyarray[k][d] == 5)
- System.out.print("興");
- else if(copyarray[k][d] == 6)
- System.out.print("中");
- else if(copyarray[k][d] == 7)
- System.out.print("華");
- else if(copyarray[k][d] == 10)
- System.out.print("一");
- else
- System.out.print("一");
- }
- System.out.println();
- }
- }
- if(j != 4 && array[i][j+1] == array[i][j]+1) visit(i,j+1);
- if(i != 3 && array[i+1][j] == array[i][j]+1) visit(i+1,j);
- copyarray[i][j] = 10;
- }
- /*
- * 主調方法
- */
- public void test(){
- initcopy();
- visit(startI,startJ);
- System.out.println("共有 "+count+" 種");
- }
- }
結果截圖:
4.標題: 顛倒的價牌
小李的店裏專賣其它店中下架的樣品電視機,可稱爲:樣品電視專賣店。
其標價都是4位數字(即千元不等)。
小李爲了標價清晰、方便,使用了預製的類似數碼管的標價籤,只要用顏色筆塗數字就可以了(參見p1.jpg)。
這種價牌有個特點,對一些數字,倒過來看也是合理的數字。如:1 2 5 6 8 9 0 都可以。這樣一來,如果牌子掛倒了,有可能完全變成了另一個價格,比如:1958 倒着掛就是:8561,差了幾千元啊!!
當然,多數情況不能倒讀,比如,1110 就不能倒過來,因爲0不能作爲開始數字。
有一天,悲劇終於發生了。某個店員不小心把店裏的某兩個價格牌給掛倒了。並且這兩個價格牌的電視機都賣出去了!
慶幸的是價格出入不大,其中一個價牌賠了2百多,另一個價牌卻賺了8百多,綜合起來,反而多賺了558元。
請根據這些信息計算:賠錢的那個價牌正確的價格應該是多少?
答案是一個4位的整數,請通過瀏覽器直接提交該數字。
注意:不要提交解答過程,或其它輔助說明類的內容。
- package Forth;
- public class ReverseNumber {
- /*
- * 實現數字的翻轉
- */
- public int reverse(int n){
- int store[] = new int[4];
- int result = 0;
- int r;
- int i = 0;
- while( n != 0){ //分離每個數,存入store中
- r = n % 10;
- n = n / 10;
- store[i] = r;
- i++;
- }
- for(int k = 0; k < i; k++){
- if(store[k] == 3 || store[k] == 4 || store[k] == 7)//數字中有3、4、7的不能翻轉
- return -1;
- else if(store[k] == 6)//數字中有6,則轉爲9
- store[k] = 9;
- else if(store[k] == 9)//數字中有9,則轉爲6
- store[k] = 6;
- }
- for(int j = 0; j < i; j++){//計算翻轉後的數
- if(store[0] == 0) //最後一個數字爲0,不能翻轉
- return -1;
- if(j == 0)
- result = store[j];
- else
- result = result*10 +store[j];
- }
- // System.out.println(result);
- return result;
- }
- public void selectNum(){
- int sub = 0;
- int sub2 = 0;
- for(int i = 1000; i <= 9999; i++){//遍歷所有4位數
- if(reverse(i) == -1)
- continue;
- sub = i-reverse(i);
- if(sub < 200 || sub >= 300)
- continue;
- for(int j = 1000; j <= 9999; j++){
- if(reverse(j) == -1)
- continue;
- sub2 = reverse(j)-j;
- if(sub2 < 800 || sub2 >= 900)
- continue;
- if((sub2-sub) == 558){
- System.out.println("賠錢的正確價格爲:"+i);
- //System.out.println("賺錢的正確價格爲:"+j);
- }
- }
- }
- }
- }
答案:9088