Educational Codeforces Round 76 (Rated for Div. 2) D题

 

 Meaning of the questions:

You give the n levels, each with a monster, a monster of attack [i], n you have a hero, a hero per attack, and fatigue values, as long as the hero of attack higher than the monster even played, while fatigue minus one day, can only play a hero, a hero can play several levels (as long as the fatigue range), then beat the challenges of today's heroes is over, go to the next day. Minimum asked how many heroes need to play through all the levels.

Ideas: first with an array. When patience ran out of the same value, the greater the damage. · Then ran out of the suffix pre array of arrays, meaning pre array is: patience certain value, maximum attack. · Monster then run through an array of complexity O (n) a. When a [i] is greater than the value pre monster array during a day attack, the process proceeds to the next day. [Disguised] [half title is more difficult to describe QAQ]

Code:

 1 #include<bits/stdc++.h>
 2  
 3 using namespace std;
 4  
 5 #define int long long
 6 const int N=22e4;int n;
 7 int arr[N];
 8 int pre[N];
 9 int str[N];
10 int slove(){
11     int ans=1;//总天数 
12     int last_time=-1;
13     int maxn=0;
14     for(int i=0;i<n;i++){
15         maxn=max(maxn,arr[i]);
16         if(pre[i-last_time]<maxn){
17             last_time=i-1;
18             ans++;
19             maxn=arr[i];
20         }
21         if(pre[1]<arr[i]){
22             return -1;
23         }
24     }
25     return ans;
26 }
27 signed  main(){
28     ios::sync_with_stdio(0);
29     int _;
30     cin>>_;
31     while(_--){
32         cin>>n;
33         int maxn1=0,maxn2=0;
34         for(int i=0;i<=n+10;i++)    
35             arr[i]=0,str[i]=0,pre[i]=0;
36         for(int i=0; I <n-; I ++ ) {
 37 [              CIN >> ARR [I];
 38 is              maxn1 = max (maxn1, ARR [I]);
 39          }
 40          int m;
 41 is          CIN >> m;
 42 is          for ( int I = 0 ; I <m; I ++ ) {
 43 is              int X, Y;
 44 is              CIN >> >> X Y;
 45              maxn2 = max (maxn2, X);
 46 is              pre [Y] = max (pre [Y], X); // when the value of the same patient, the greater the attack 
47          }
 48          IF (maxn1> maxn2) {
49             cout<<"-1"<<'\n';
50             continue;
51         }
52         for(int i=n-1;i>0;i--){
53             pre[i]=max(pre[i+1],pre[i]);// 
54         }
55         cout<<slove()<<'\n';
56     }
57     return 0;
58 }

 

Guess you like

Origin www.cnblogs.com/pengge666/p/11856316.html