2017 Blue Bridge Cup race simulation

1. Title: calculate the age of


the British mathematician De Morgan was born in the early 19th century (ie, 18xx years).
It is very talented when he was young. Someone once asked his age, he replied:
"To the square x of that year, I happen to be x years old."


Please you do the math, De Morgan was born in the end in what year.
The title refers to the age of the age.


Please fill represent four-digit year of his birth, do not fill any extra content.

Idea: by calculator, only 43, 44 meet the requirements of these two numbers, 42 * 42 * 45 = 2025 = 1764,45

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		for (int i=43; i<45; i++) {
			int year = i * i - i;
			//1806
			//1892
			System.out.println(year);
		}
	}
}
Since the early 19th century, it is 1806


2. Title: Guess formula


you must remember to calculate elementary school learned of the multiplication process, such as:


   273
the X-15
------
  1365
  273
------
  4095
  
Please observe the following multiplication formula


    ***
the X-* **
--------
    ***
   ***
  ***
--------
  *****
  
asterisks representatives of a number, pay attention to these asterisks in
the 0-9 each number with exactly two times.
(Font arising as a result of alignment issues, see Figure p1.jpg)


Please write result of this formula finally calculated, is that the 5-digit number is?


Note: You only need to fill in a whole number, do not fill in any extra content. Such as captions.


import java.util.Arrays;

public class Main {

	static int[] num = new int[3];
	static int[] visit = new int[10];
	public static void main(String[] args) {
		for (int i=100; i<=999; i++) {
			num[0] = i % 10;
			num[1] = i / 10 % 10;
			num[2] = i / 100;
			for (int j=100; j<=999; j++) {
				Arrays.fill(visit, 0);
				cal2(i);
				cal2(j);
				//中间计算过程的积都是三位数,则继续进行
				if (cal(j % 10) && cal(j / 10 % 10) && cal(j / 100)) {
					cal2(i * j);
					int k;
					for (k=0; k<10; k++) {
						if (visit[k] != 2)
							break;
					}
					if (k == 10) {
						//179*224=40096
						System.out.println(i + "*" + j + "=" + i * j);
					}
				}
			}
		}
	}
	//标记因子和积的各个位数
	private static void cal2(int x) {
		while (x != 0) {
			visit[x % 10]++;
			x /= 10;
		}
	}
	//标记中间计算过程的各个位数,如果中间计算过程中有积为4位数,则返回false
	private static boolean cal(int x) {
		int temp = 0;
		for (int i=0; i<3; i++) {
			int y = num[i] * x + temp;
			temp = y / 10;
			if (i == 2 && temp != 0)
				return false;
			visit[y % 10]++;
		}
		return true;
	}
}

3. Title: arrangement ordinal


certain archaeological activities X galaxies discovered traces of prehistoric intelligence.
This is used to count the number of symbols, through analysis of its counting law as follows:
(For ease of presentation, we use these strange symbols instead of a ~ q)


abcdefghijklmnopq represents 0
abcdefghijklmnoqp represented. 1
abcdefghijklmnpoq represents 2
abcdefghijklmnpqo represented. 3
abcdefghijklmnqop represented. 4
abcdefghijklmnqpo represents 5
abcdefghijklmonpq represent 6
abcdefghijklmonqp represent 7
.....


carved on a stone symbol is:
bckfqlajhemgiodnp


Please work out the numbers it represents how much?


Please submit the integer, do not fill in any extra content, such as notes or comments.

Ideas: violence simulation time is too long, with Cantor Expand

X = a [n] * (n-1)! + A [n-1] * (n-2)! + ... + a [i] * (i-1)! + ... + a [ 1] * 0!, where a [i] is an element of the current is not present in the first few rows (from zero). This is Cantor Expand


{1,2,3,4, ..., n} represents 2,3, ..., n, are arranged as {1,2,3} in ascending order according to a total of six. 123,132,213,231,312 321

Figures represent 123 456 is the decimal number corresponding to the arrangement together with a.
The correspondence between Cantor they may start to find.
If I want to know 321 {1,2,3} is the first of several small numbers consider this:
3 is a first, when the first number is less than 3, then the number of permutations of less than 321 such as 123, 213, the number is less than 1, 2 3. So there are 2 * 2! Months. Second look less than 2: less than the number 2 only is a 1, it is 1 * 1 = 1 Therefore, the number of permutations of less than 321 {1,2,3} 2 * 1 * 2 + 1 =!!! 5. So 321 is the first of six small number. 2 * 2! * 1 + 1! + 0 * 0! Cantor is expanded.
Another example: 1324 is the number of {1,2,3,4} arrangement of several large numbers:! A is a number of not less than 1, a * 0 0 3 3 The second is less than number 3, 1 and 2, but 1 have been in the first place, so there is only one number 21 * 2!. The third number is 2 is less than 1 2, 1 in the first place but, it is the number 0 1 0 *!, * 3 0 so there are arranged smaller than 1324! + 1 * 2! * 0 + 1! = 2, 1324 is the third decimal.
a [i] of expression and presentation may be the beginning of a little different, but the effect is the same
public class Main {
	
	public static void main(String[] args) {
		long[] a = new long[18];
		a[0] = 1;
		for (int i=1; i<=17; i++) {
			a[i] = a[i-1] * i;
		}
		long total = 0;
		String str = "bckfqlajhemgiodnp";
		for (int i=0; i<17; i++) {
			int sum = 0;
			//求第i个元素在未出现的元素中排名第几
			for (int j=i+1; j<17; j++) {
				if (str.charAt(j) < str.charAt(i))
					sum++;
			}
			total += sum * a[16-i];
		}
		//22952601027516
		System.out.println(total);
	}
}

4. Title: string comparison


we need a new string comparison function compare (s1, s2).
This function requirements are:
1. it returns an integer that represents the result of the comparison.
2. The result is a positive value, a string before the large, negative, after a string of large, otherwise the same.
It represents the absolute value of 3. Results: two strings found in the first few letters of the range.


Here is the code. Data on the surface of the problem, the result is:
-3
2
5


carefully read the source code, to fill in the missing crossed position code.


-------------------------------------------------
the Java language code:


static int Compare (String S1, S2 String)
{
if(s1==null && s2==null) return 0;
if(s1==null) return -1;
if(s2==null) return 1;

if(s1.isEmpty() && s2.isEmpty()) return 0;
if(s1.isEmpty()) return -1;
if(s2.isEmpty()) return 1;

char x = s1.charAt(0);
char y = s2.charAt (0);

if(x<y) return -1;
if(x>y) return 1;

int t = compare(s1.substring(1),s2.substring(1));
if(t==0) return 0;

return ____________________; // fill in the blank position
}


public static void main (String [] args)
{
System.out.println(compare("abc", "abk"));
System.out.println(compare("abc", "a"));
System.out.println(compare("abcde", "abcda"));
}


---------------------------
C/C++ 语言代码:
int compare(const char* s1, const char* s2)
{
if(s1==NULL && s2==NULL) return 0;
if(s1==NULL) return -1;
if(s2==NULL) return 1;

if(*s1 == 0 && *s2== 0) return 0;
if(*s1 == 0) return -1;
if(*s2 == 0) return 1;

if(*s1<*s2) return -1;
if(*s1>*s2) return 1;

int t = compare(s1+1,s2+1);
if(t==0) return 0;

return __________________________; // fill in the blank position
}




int main ()
{
printf("%d\n", compare("abc","abk"));
printf("%d\n", compare("abc","a"));
printf("%d\n", compare("abcde","abcda"));
0 return;
}


Note:
only submit underlined part missing codes, do not include existing code or notation.
Do not superfluous to write any notes or descriptive text.


Note Select the language you use.
//注意把符号写在前面
return t > 0 ? ++t : --t;

5. Title: Mortgage calculation


matching principal and interest repayment method of bank loans is:
monthly fixed amount, at the agreed installments just yet finished (last month there may be a small fraction out).


For example, Xiao Ming in bank loan 10,000 yuan. Annualized rate loans at 5%, the loan period is 24 months.
The banks will be settled in a month:
settlement method is: the principal interest calculation produced this month: Principal x (APR / 12)
the principal balance of this month are: principal + interest - monthly fixed yet the amount of
calculation results are rounded to "divide."


Calculated, in this case, a fixed repayment should be: 438.71


In this way, when the principal balance of the settlement is the first month:
9602.96
second month settlement:
9204.26
first three months of settlement:
8803.9
....
last If a fixed monthly amount based upon the repayment of the last principal balance is still $ 0.11,
but if you adjust the fixed repayment amounted to 438.72, the last month the bank also will be more than 0.14 yuan.
The bank will choose the final settlement of the principal amount of the absolute value of the minimum conditions set fixed monthly repayment amount.
If there are two cases last principal the same absolute value, then choose the repayment plan with less.


This problem is known task annualized interest rates, repayment periods, seeking a fixed monthly repayment amount.


Let's assume Bob loan $ 10,000, namely: = initial principal amount of $ 10,000.
Annualized interest rate is the number of units per cent.
How many units of periods of months.


Input 2 lines,
first conduct a decimal r, it represents an annual rate of a few percent. (0 <r <30)
a second conduct an integer n, the repayment period. (6 <= n <= 120 )


required output is an integer representing the monthly amount (unit: minute)


example:
Input:
4.01
24


program should output:
43429


Another example:
Input:
6.85
36


program should output:
30,809


resources for:
peak memory consumption (including virtual machines) <256M
the CPU consumption <1000ms




in strict accordance with the required output, not superfluous to print something like: "Please enter ..." unwanted content.


All source code in a single file, through debugging, submit the copy source.
java player Note: Do not use a package statement. Do not use jdk1.7 and above features.
java players Note: the main class name must be: Main, or else the invalid code processing.


c / c ++ players Note: main function needs to return 0
c / c ++ players Note: Use only ANSI C / ANSI C ++ standard, do not call a special function depends on the build environment or operating system.
c / c ++ player Note: all dependent functions must explicitly in the source file #include <xxx>, can not be provided by engineering omitted common header file.


When the submission process, pay attention to select the desired type of language and compiler type
6. Title: slide to unlock


slide to unlock the smartphone is a frequently-used functions. You need a 3x3 dot matrix, starting from any point, a point repeatedly to move has not been a "neighbor" of. The composition of these points across to the broken line there, if all consistent with a preset fold line on the pattern, direction, then the phone will be unlocked.


The so-called two-point "adjacent": if and only if there is no order on these two points for the end of the line has not been the point.


In addition, many mobile phones have agreed: this polyline also need to go through at least four points.


For convenience of description, we gave it nine points from top to bottom, left to right are numbered 1-9. That is arranged as follows:


. 1 2 3
. 4. 5. 6
. 7. 8. 9


then 1-> 2-> 3 is illegal, because of insufficient length.
1-> 3-> 2-> 4 is illegal, as 1-> 3 has not been passed through the point 2.
2-> 4-> 1-> 3-> 6 is legal, as 1-> 3 across the point 2 has been.


God has a big calculated: a total of 389,112 kinds of different unlocking solution. When no clue, in order to unlock the violence is indeed difficult.
Hi small but very curious, he wanted to know when the case has been part of the polyline glance, how many different options.
Unfortunately, the small Hi see section polyline neither necessarily contiguous, do not know the direction.


See, for example, 1-2-3 and 4-5-6,
then 1-> 2-> 3-> 4-> 5-> 6,1-> 2-> 3-> 6-> 5-> 4, 3-> 2-> 1-> 6-> 5-> 4-> 8-> 9 are all possible solutions.




Your task is to write a program, according to fragmentary glimpse of the segment has been seeking to unlock the number of possible solutions.


Input:
Each test data of the first line is an integer N (0 <= N <= 8), representing the number of small Hi see line segment.
The following N lines contains two integers X and Y (1 <= X, Y <= 9), representing small Hi see point X and the point Y is directly connected.


Output:
For each set of output data the number of valid unlocking solution.




For example:
Input:
. 8
. 1 2 2. 3
. 3. 4. 4. 5
. 5. 6. 6. 7
. 7. 8. 8. 9


program should output:
2


For another example:
Input:
. 4
2. 4
2. 5
. 8. 5
. 8. 6


procedure should output:
258




Resources for:
peak memory consumption (including virtual machines) <256M
the CPU consumption <1000ms




in strict accordance with the required output, not superfluous to print something like: "Please enter ..." unwanted content.


All source code in a single file, through debugging, submit the copy source.
java player Note: Do not use a package statement. Do not use jdk1.7 and above features.
java players Note: the main class name must be: Main, or else the invalid code processing.


c / c ++ players Note: main function needs to return 0
c / c ++ players Note: Use only ANSI C / ANSI C ++ standard, do not call a special function depends on the build environment or operating system.
c / c ++ player Note: all dependent functions must explicitly in the source file #include <xxx>, can not be provided by engineering omitted common header file.


When the submission process, pay attention to select the desired language and compiler type type.

Published 477 original articles · won praise 34 · views 210 000 +

Guess you like

Origin blog.csdn.net/qq_25605637/article/details/67633426