Cool liver competition

Keywords: C++

For this competition, I really rowed a little bit. I did two questions. When I did the third question, I didn't know where I was stuck. Then my family came to the guests and was taken out for dinner. ε = ('ο ')) alas!!!

B - Just Eat It!

This problem is a classic DP problem. I'm not very familiar with recursion. I have to find the state transfer equation of the problem.

B[ i ] = max{ A[ i ] , B[ i - 1] + A[ i ] };

Let B [i] denote the maximum sum of the continuous sequences with a [i] as the end. By setting a B array, the maximum continuous subsequence sum of the array is actually the maximum value in the B array, and the maximum value found may also be the sum of all, so first set a number to count the number that has been continuous, exclude this situation, and then calculate the total previously And compare them to get the answer.

(I see this method from the algorithm notes, and I haven't seen too much...)

 

#include<bits/stdc++.h>
using namespace std;
const int xa=2e5+5;
long long a[xa],b[xa];
int main()
{
    int t;
    cin>>t;
    long long n;
    long long sum;
    long long shu;
    bool pan;
    while(t--){
        cin>>n;
        sum=0;
        shu=0;
        pan=false;
        for(int i=0;i<n;i++){
            cin>>a[i];
            sum+=a[i];
        }
        b[0]=a[0];
        for(int i=1;i<n-1;i++){
            if(a[i]<=b[i-1]+a[i]){
                b[i]=b[i-1]+a[i];
                shu++;
            }else{
                b[i]=a[i];
                shu=0;
            }
        }
        if(shu==n){
            pan=true;
        }
        int k=0;
        for(int i=1;i<n;i++){
            if(b[i]>b[k]){
                k=i;
            }
        }
        if(b[k]>=sum&&!pan){
            cout<<"NO"<<endl;
        }else{
            cout<<"YES"<<endl;
        }
    }
}

 

E - Deadline

 

This problem seems very simple, but I didn't know how to solve this mathematical problem in the competition. When I saw the competition, I went to see problem B in a hurry.

Listen to the big boys. This is mean inequality

From the meaning of the question, n > = x + [D / (x + 1)] = x + 1 [D / (x + 1)] - 1 > = 2sqrt (d) - 1;

So it's solved. ~

Whining.

#include<bits/stdc++.h>
using namespace std;
int t;
long long n,d;
int main(){
    cin>>t;
    while(t--){
        cin>>n>>d;
        if((n+1)*(n+1)/4>=d)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
}    

Posted by richo89 on Sat, 18 Jan 2020 10:01:36 -0800