Director Zheng's series of stories - escape from the maze

Director Zheng's series of stories - escape from the maze

Topic:
  Factory Director Zheng has not changed.
  is still the fake factory director and a real coder.
  What has changed is his hobby
  . Now he does not study chess, but plays games instead!
  Recently, Director Zheng fell in love with the game Escape from the Maze. He played it day and night just to achieve his goal: 10 million, because this figure is as much as his annual income from Tencent.
  However, when he ran to 9999999, a lot of boxes suddenly appeared on the game screen, and Director Zheng had to eliminate all these boxes to continue playing the game. These boxes are arranged in a row, and each box has a number on it, and each number represents the number of times the box needs to be clicked before it disappears. When each box is clicked, the corresponding number will be reduced by 1, and the number of the box on the right will be reduced by 1 at the same time. When the number of the box becomes 0, it will disappear. It should be noted that if there is no box on the right or the box on the right has disappeared, the current box cannot be operated (the "right" mentioned above only refers to the right side next to it, and the separated ones are not counted).
  Now that the information of these boxes is known, can Director Zheng successfully eliminate all the boxes and continue to realize his million-dollar dream?
input:
The input first contains a positive integer T, indicating that there are T groups of test samples;
each group of samples has two lines, the first line is an integer n, representing n boxes; the second line has n numbers ai, representing The number of times each box needs to be clicked.

[Technical Specification]
T<=100
1 <= n <= 10 ^ 6
0 <= ai <= 10 ^ 9 (1 <= i <= n)
output:
For each sample, if Mr. Zheng can successfully eliminate These boxes escape successfully, please output "yeah~ I escaped _ ", otherwise output "I will never go out T_T".
sample:

input output
2 yeah~ I escaped ^ _ ^
2 I will never go out T_T
2 2
2
1 2

Idea:
Every time the right side will decrease, so just keep clicking on the left square.
There is no way to eliminate all the boxes with an odd number. Only when the maximum number is equal to the sum of all remaining numbers can all be eliminated.
code:

#include <stdio.h>
#include <math.h> 
int main()
{
    
    
    int t,n,i,a,b;
    scanf("%d",&t);
    while(t--)
    {
    
    
        scanf("%d",&n);
        scanf("%d",&a);
        for(i=1;i<n;++i)
        {
    
    
            scanf("%d",&b);
            a=abs(a-b);每次减少后还剩的箱子
        }
        if(a)
		{
    
    
			printf("I will never go out T_T\n");
		}
        else
		{
    
    
			printf("yeah~ I escaped ^_^\n");
		}
    }
}

Guess you like

Origin blog.csdn.net/qq_63294590/article/details/124829818