First line (B) : There are N working areas in Beijing, forming a ring. Bytebus is a commuter bus that travels between each working area in the order of each working area. The ith working area has gas[I] liters.

You have a Bytebus with unlimited tank capacity, and it costs cost[I] liters of gas to get from station I to station I +1. You start out in one of the fields with an empty tank. If you are

If you can drive around the loop once, return the number of the starting working area, otherwise return -1.

Input:

Gas = [1, 2, 3, 4, 5]

Cost =,4,5,1,2 [3]

Output: 3

Course two: there are 1000 bottles of medicine, 999 of which are non-toxic and only one is toxic. Mice are known to die within an hour of drinking the poison, so you’re given 10 mice and one hour to find the poisoned bottle. Instructions: Each bottle was large enough for each mouse to take at the same time, feeding time was negligible, and the animals’ stomachs were large enough to drink many bottles.

Lane 3 (T) : The car can turn left, right, and forward, and the car’s position is determined by an X and y coordinate system and an orientation. N, S, W, and E in the geographical direction represent up, down, left, and right, respectively.

Example: Position coordinates X=0, Y=0, N. Represents the car at the origin of the frame, facing up.

To control the movement of the car, a simple string of letters is transmitted. The letters sent are L, R and M. L and R indicate turning the car 90 degrees to the left and right respectively. But not from its place; M means one unit forward, holding the same direction.

Expected input:

The first line inputs the initial size of the car as X=10, Y=10, N

The second line input the instruction MMLMMR

Expected output:

The coordinates and position of the car X=8, Y=12, N

Requirements:

Pay attention to the quality of your code

2. No duplicate code

3. Use object-oriented programming

Reference: blog.csdn.net/hongmin118/…

The answer, first think about yourself. I think the average person can use brute force to get the final answer, but in the computer stage of the interview, the interviewer likes the result with the minimum time and space complexity. Because I’m normal, the first thing I wanted to do was solve the problem first. Maybe you’re smarter than me, so if you don’t come up with an answer, Google it.