Summer training CF sets of questions

CodeForces 327A

The meaning of problems: there are number of n, is 0 or 1, then the operation must be performed, a reversing section, which becomes the number 0, 1 becomes 0, and quantity of at most 1

Ideas: First, I wrote the maximum field and, as if written back rub, and then I changed to violence, because this range is only 100, write n ^ 3 are all right, so we left the first floor enumeration range, the second layer enumerate the right range, and then we left the third layer number of 1 and 0 in the middle of recording, the number 1 to the right

 

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define maxn 100005
#define mod 1000000007
using namespace std;
typedef long long ll;
ll a[1005],num,n;
int main(){
    scanf("%lld",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    ll mx=0;
    for(int i=1;i<=n;i++){
        for(int j=i;j<=n;j++){
            ll shu=0;
            for(int k=1;k<i;k++){
                if(a[k]) shu++;
             }
             for(int k=i;k<=j;k++){
                if(a[k]==0) shu++;
             }
             for(int k=j+1;k<=n;k++){
                if(a[k]) shu++;
             }
             mx=max(shu,mx);
        }
    }
    printf("%lld",mx);
} 
View Code

 

 

CodeForces 854C

Meaning of the questions: There are n planes, aircraft are now for some reason can only be delayed until after the departure time k + 1, a time only starting one, each aircraft has a number of flying one minute late loss, initially by aircraft sequencing timetable, now ask how you row table minimum loss

Ideas: First, we know that the beginning is 12345, if k is 2, then we only 34,567, but we have to how to arrange it, we can clearly know that everyone is one minute loss how much, so we certainly make the biggest loss as little as possible, because the difference is fixed 34567--12345 difference and 10, but we are going to arrange this difference to what number, we certainly try to put the difference between a small loss, so we have to row a sequence, we find the value closest to the current number, but we find is a problem that can only be used once, run out will remove, and we can not find traverse , there is a good thing is set, we can use the log level delete, set.lower_bound log level will be able to find a good solution to this matter in line with these requirements

 

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#define maxn 300005
#define mod 1000000007
using namespace std;
typedef long long ll;
struct sss
{
    ll id;
    ll x;
}a[maxn];
ll n,m;
ll vis[maxn];
set<ll> q;
int cmp(struct sss x,struct sss y){
    return x.x>y.x;
}
int main(){
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=n;i++){
        q.insert(i+m);
    }
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i].x);
        a[i].id=i;
    }
    sort(a+1,a+n+1,cmp);
    ll sum=0;
    for(int i=1;i<=n;i++){
        ll x=*q.lower_bound(a[i].id);
        //set<ll>::iterator t1=q.upper_bound(a[i].x);    
        sum+=(x-a[i].id)*a[i].x;
        vis[a[i].id]=x;
        q.erase(x);
    }
    printf("%lld\n",sum);
    for(int i=1;i<=n;i++){
        printf("%lld ",vis[i]);
    }
} 
View Code

 

Guess you like

Origin www.cnblogs.com/Lis-/p/11330620.html