Blue Bridge Cup java 2018

The video of the Java Blue Bridge Cup explains the code.

1. Flight time

[Problem background]
Xiao H went to the United States to participate in the Blue Bridge Cup International Competition. Xiao H ’s girlfriend found that Xiao H departed at 10 am and arrived at the United States at 12 am, so she lamented that “the plane is flying really fast now, and you can arrive in the United States in two hours.”

Xiao h was terrified of supersonic flight. After careful observation, it was found that the takeoff and landing times of the aircraft are all local time. Due to the 12-hour time difference between Beijing and the eastern United States, the aircraft needs a total of 14 hours of flight time.

Soon after, H's girlfriend went to exchange in the Middle East. Xiao H did not know the time difference between the Middle East and Beijing. But Xiao H got the take-off and landing time of his girlfriend's round-trip flight. Xiao H wants to know what the girlfriend's flight time is.

[Description of Problem]
For a flight that may cross a time zone, a given round trip time is given. Assuming that the plane's round-trip flight time is the same, find the plane's flight time.

[Input format]
Read data from standard input.

An input contains multiple sets of data.

Enter the first line as a positive integer T, indicating the number of input data groups.

Each set of data contains two rows, the first line is the take-off and landing time of the outbound trip, and the second line is the take-off and landing time of the return trip.

The format of the take-off and landing time is as follows

h1: m1: s1 h2: m2: s2
or
h1: m1: s1 h3: m3: s3 (+1)
or
h1: m1: s1 h4: m4: s4 (+2)
means the flight is at local time h1 m1 Take off in s1 seconds,

The first format means landing at h2 o'clock m2 min s2 sec on the day of local time

The second format means landing at h3: m3: s3 seconds the next day at local time.

The third format means landing on the third day of local time at h4m4m4s4 seconds.

For all the time given in the form of hⓂ️s in this topic, guarantee (0 <= h <= 23, 0 <= m, s <= 59).

[Output format]
Output to standard output.

For each set of data, a line of time hh: mm: ss is output, indicating that the flight time is hh hours mm minutes ss seconds.

Note that when the time is a single digit, leading zeros must be padded. For example, three hours, four minutes and five seconds should be written as 03:04:05.

[Sample input]
3
17:48:19
21:57:24 11:05:18
15:14:23 17:21:07 00:31:46 (+1)
23:02:41 16:13:20 (+1)
10:19:19 20:41:24 22:19:04 16:41:09
(+1)

[Sample output]
04:09:05
12:10:39
14:22:05

public class HangBan {
	static Scanner sc=new Scanner(System.in);
	public static void main(String[] args) throws Exception {
		
		int T=sc.nextInt();
		sc.nextLine();
		for(int i=0;i<T;i++) {
			long time1=getTime();
			long time2=getTime();
			long t=(time1+time2)/2;
			System.out.printf("%02d:%02d:%02d\n",t/3600,t/60%60,t%60);
		}
	}

	private static long getTime() throws Exception {
		String line=sc.nextLine();
		String[] split=line.split(" ");
		SimpleDateFormat format=new SimpleDateFormat("HH:mm:ss");
		Date t1=format.parse(split[0]);
		Date t2=format.parse(split[1]);
		int d=0;
		if(split.length==3) {
			d=Integer.parseInt(split[2].substring(2,3));
			
		}
		return d*24*3600+t2.getTime()/1000-t1.getTime()/1000;
	}
}

2. Three-body attack

【Description】 The
three-body man will attack the earth. In order to resist the attack, the Earthmen sent A × B × C warships to form a cube in row A, row B and row C in space. Among them, the life value of the battleship in row i, row j and column k (denoted as battleship (i, j, k)) is d (i, j, k).

The three-body man will launch m rounds of "cube attacks" on the earth, each attack will cause the same damage to all battleships in a small cube. Specifically, the round t attack is described by 7 parameters lat, rat, lbt, rbt, lct, rct, ht;
all satisfy i ∈ [lat, rat], j ∈ [lbt, rbt], k ∈ [lct, rct ] 'S battleship (i, j, k) will be damaged by ht. If the total damage received by a warship exceeds its defense power, the warship will explode.

The Earth Commander hopes you can tell him after which round of attack the first explosive ship exploded.

[Input format]
Read data from standard input.
The first line contains 4 positive integers A, B, C, m; the
second line contains A × B × C integers, where the ((i − 1) × B + (j − 1)) × C + (k − 1) +1 number is d (i, j, k);
lines 3 to m + 2 and line (t − 2) contains 7 positive integers lat, rat, lbt, rbt, lct, rct , ht.

[Output format]
Output to standard output.
It is output after which round of attack the first warship exploded. Ensure that such a battleship must exist.

[Sample input]
2 2 2 3
1 1 1 1 1 1 1 1 1
1 2 1 2 1 1 1
1 1 1 2 1 2 1
1 1 1 1 1 1 2

[Sample output]
2

[Sample Explanation]
After the second round of attack, the battleship (1,1,1) received a total of 2 damage, which exceeded its defense and caused an explosion.

[Data convention]
For 10% of data, B = C = 1;
for 20% of data, C = 1;
for 40% of data, A × B × C, m ≤ 10,000;
for 70% of data, A, B, C ≤ 200;
for all data, A × B × C ≤ 10 ^ 6, m ≤ 10 ^ 6, 0 ≤ d (i, j, k), ht ≤ 10 ^ 9.

Resource convention:
peak memory consumption (including virtual machine) <256M
CPU consumption <3000ms

I think this question is so difficult, it's not something my brain can figure out.
First, the three-layer for loop is broken and brute force cracked, but only 40% of the data can pass

搜到的暴力破解法
public class Santi {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int a, b, c, m;
		a = input.nextInt();
		b = input.nextInt();
		c = input.nextInt();
		m = input.nextInt();
		int[][][] martix = new int[a + 1][b + 1][c + 1];

		for (int i = 1; i <= a; ++i)
			for (int j = 1; j <= b; ++j)
				for (int k = 1; k <= c; ++k)
					martix[i][j][k] = input.nextInt();

		int lat, rat, lbt, rbt, lct, rct, ht;
		int flag = 0;
		for (int p = 1; p <= m; ++p) {
			lat = input.nextInt();
			rat = input.nextInt();
			lbt = input.nextInt();
			rbt = input.nextInt();
			lct = input.nextInt();
			rct = input.nextInt();
			ht = input.nextInt();
			for (int i = lat; i <= rat; ++i)
				for (int j = lbt; j <= rbt; ++j)
					for (int k = lct; k <= rct; ++k) {
						martix[i][j][k] -= ht;
						if (martix[i][j][k] < 0) {
							flag = p;
							break;
						}
					}

			if (flag != 0)
				break;
		}
		System.out.println(flag);
	}
}

Optimization: The first dichotomy is
to follow the bad. To understand the two-dimensional differential
hearing for more than half an hour, it is too difficult to give up.

Published 44 original articles · Likes2 · Visits 540

Guess you like

Origin blog.csdn.net/qq_43699776/article/details/105155381