# 1, The blue bridge cup test questions are divided into candy [the fifth session], [provincial competition], [group B]

### (1) Problem description

Time limit: 1.0s memory limit: 256.0MB

There are n children sitting in a circle. The teacher gives each child an even number of sweets at random, and then plays the following game:

Each child gave half of his candy to the child on the left.

After a round of sugar sharing, the child with an odd number of sugars is supplied with one candy by the teacher, which becomes even.

Repeat the game until all the children have the same number of sweets.

Your task is to predict how many sweets the teacher needs to reissue under the known initial candy situation.

Format requirements

The program first reads in an integer n (2 < n < 100), indicating the number of children.

Then there is a line of N even numbers separated by spaces (each even number is no more than 1000 and no less than 2)

The program is required to output an integer indicating the number of sweets that the teacher needs to reissue.

For example: Enter

3

2 2 4

The program should output:

4

Resource agreement:

Peak memory consumption (including virtual machine) < 256M

CPU consumption < 1000ms

Please output in strict accordance with the requirements, and do not print like "please input..." Superfluous content.

All code is placed in the same source file. After debugging, the copy is submitted to the source code.

Note: do not use package statements. Do not use jdk1 7 and above.

Note: the name of the Main class must be: Main, otherwise it will be treated as an invalid code.

### (2) Code implementation

import java.util.Scanner; public class Main { static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { int N = scanner.nextInt(); int[] arr = new int[N]; int[] t = new int[N]; //Record half the candy int ans = 0; for (int i = 0; i < arr.length; i++) { arr[i] = scanner.nextInt(); } while(true) { if (check(arr)) { //Jump out of the loop when conditions are met break; } //Divide everyone's candy in half (halve) for (int i = 0; i < arr.length; i++) { arr[i] = arr[i]/2; t[i] = arr[i]; } //The child on the left gets points of candy arr[0] = arr[0]+t[N-1]; for (int i = 1; i < arr.length; i++) { arr[i] = arr[i]+t[i-1]; } //The teacher added sugar for (int i = 0; i < arr.length; i++) { if (arr[i]%2==1) { arr[i]++; ans++; } } } System.out.println(ans); scanner.close(); } private static boolean check(int[] arr) { for (int i = 1; i < arr.length; i++) { if (arr[i]!=arr[i-1]) { return false; } } return true; } }

# 2, Blue bridge cup test questions previous real questions spiral line [ninth session] [provincial competition] [group B]

### (1) Problem description

Time limit: 1.0s} memory limit: 256.0MB

The spiral polyline as shown in the figure passes through all integral points on the plane exactly once.

For the whole point (X, Y), we define its distance from the origin. dis(X, Y) is the length of the spiral line segment from the origin to (X, Y).

For example, dis(0, 1)=3, dis(-2, -1)=9

Given the coordinates of the whole point (X, Y), can you calculate dis(X, Y)?

Input format

X and Y

For 40% data, - 1000 < = x, y < = 1000

For 70% of data, - 100000 < = x, y < = 100000

For 100% data, - 1000000000 < = x, y < = 1000000000

Output format

Output dis(X, Y)

sample input

0 1

sample output

3

### (2) Code implementation

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); long X = in.nextLong(); long Y = in.nextLong(); long n = Math.max(Math.abs(X) , Math.abs(Y)); long Sn = 4*(n-1)*n; long sum = 0; long px = -n, py = -n; long d1 = X-px, d2 = Y-py; if (Y > X) { sum += (d1+d2); } else { sum += (8*n-d1-d2); } System.out.println(sum + Sn); } }

# III. blue bridge cup test questions previous real questions date [8th session] [provincial competition] [group B]

### (1) Problem description

Time limit: 1.0s} memory limit: 256.0MB

Xiao Ming is sorting out a batch of historical documents. Many dates appear in these historical documents. Xiao Ming knows that these dates are from January 1, 1960 to December 31, 2059. What bothers Xiao Ming is that the formats of these dates are very different, including year / month / day, month / day / year and day / month / year. What's more troublesome is that the first two digits of the year are omitted, so that there are many possible dates corresponding to a date in the literature.

For example, 02 / 03 / 04 may be March 4, 2002, February 3, 2004 or March 2, 2004.

Given a date in the literature, can you help Xiao Ming judge which possible dates correspond to it?

Input format

----

A date in the format "AA/BB/CC". (0 <= A, B, C <= 9)

Input format

----

Output several different dates, one line for each date, in the format of "yyyy MM DD". Multiple dates are arranged from morning to night.

sample input

----

02/03/04

sample output

----

2002-03-04

2004-02-03

2004-03-02

Resource agreement:

Peak memory consumption (including virtual machine) < 256M

CPU consumption < 1000ms

Please output in strict accordance with the requirements, and do not print like "please input..." Superfluous content.

be careful:

The main function needs to return 0;

Only ANSI C/ANSI C + + standards are used;

Do not call special functions that depend on the compilation environment or operating system.

All dependent functions must be explicitly in the source file #include < XXX >

Common header files cannot be omitted through engineering settings.

When submitting programs, pay attention to selecting the desired language type and compiler type.

### (2) Code implementation

import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String s = scanner.nextLine(); int year = 0; int month = 0; int day = 0; year = (s.charAt(0) - '0') * 10 + (s.charAt(1) - '0'); month = (s.charAt(3) - '0') * 10 + (s.charAt(4) - '0'); day = (s.charAt(6) - '0') * 10 + (s.charAt(7) - '0'); String case1 = int2String(year,month,day); String case2 = int2String(day,year,month); String case3 = int2String(day,month,year); Set<String> set = new TreeSet<String>(); if(case1 != "") set.add(case1); if(case2 != "") set.add(case2); if(case3 != "") set.add(case3); for (String s1 : set) { System.out.println(s1); } } static String int2String(int year, int month, int day) { if(year >= 0 && year <= 59){ year += 2000; }else if(year >= 60 && year <= 99){ year += 1900; }else{ return ""; } if(month < 1 || month > 12){ return ""; } if(day < 1 || day > 31){ return ""; } switch (month){ case 2: if(isLeap(year) && day > 29) return ""; if(!isLeap(year) && day > 28) return ""; case 4: if(day > 30) return ""; case 6: if(day > 30) return ""; case 9: if(day > 30) return ""; case 11: if(day > 30) return ""; default: break; } String year1 = year + ""; String month1 = month + ""; String day1 = day + ""; if(month1.length() == 1){ month1 = '0' + month1; } if(day1.length() == 1){ day1 = '0' + day1; } return year1 + '-' + month1 + '-' + day1; } static boolean isLeap(int year) { return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0); } }