[LeetCode Daily Question] 2383. The minimum training time required to win the game (easy)

2383. Minimum training time required to win a game


Simulation is fine, we don't consider pre-training, we only train when energy or experience is insufficient, O ( n ) O(n)O ( n ) time to get the answer.

class Solution {
    
    
public:
    int minNumberOfHours(int initialEnergy, int initialExperience, vector<int>& energy, vector<int>& experience) {
    
    
        int res=0;
        for(int i=0;i<energy.size();i++){
    
    
            // cout<<res<<" "<<initialEnergy<<" "<<initialExperience<<endl;
            if(initialEnergy<=energy[i]){
    
    
                res+=energy[i]-initialEnergy+1;
                initialEnergy=energy[i]+1;
            }
            initialEnergy-=energy[i];
            if(initialExperience<=experience[i]){
    
    
                res+=experience[i]-initialExperience+1;
                initialExperience=experience[i]+1;
            }
            initialExperience+=experience[i];
        }
        return res;
    }
};



Meng Jiangnan 【Nalan Xingde】
When the crows are exhausted, who is the cause of Xiaoli's hatred? The sudden snow turned over the catkins in the Xiangge Pavilion, and the breeze blew the plums in the vase, and the heart word has turned to ashes.

  1. Meng Jiangnan: Ci Pai name, also known as "Wang Jiangnan", "Recalling Jiangnan", "Jiangnan Good" and so on. This tune can be divided into monotone and double tone, and this one is monotone, with a total of five sentences.
  2. Faint crows: Refers to crows at dusk.
  3. Xiao Li: Stand up a little.
  4. Gall bottle: a vase with a slender neck and an enlarged belly.
  5. Heart word: Fan Shihu's "Luan Lu" records: "People in Panyu make heart word incense, use jasmine and jasmine half-opened in the net, and smell it with agarwood thinly, seal it, change it every day, and don't wait for the flowers to wilt. The fragrance of the flowers is formed." Yang Shen of the Ming Dynasty came to the conclusion based on the above records: the so-called heart characters are fragrant, and the fragrance is lingered to form the heart characters. "The "heart character" here refers to the heart character incense.

  This poem was written after Nalan Xingde's cousin Xie was elected to the palace. The author and his cousin Xie Shi grew up together. They were childhood sweethearts and childhood sweethearts. Although they did not reveal their love relationship, Nalan Xingde loved Xie Shi deeply, so after she entered the deep palace, she was in great pain. Write this word here.

Guess you like

Origin blog.csdn.net/qq_44623371/article/details/129496776