Codeforces Round #555 (Div. 3) c2 d e f

c2:Increasing Subsequence (hard version)

那边小取那边,然后相等比较后面的长度

#include<bits/stdc++.h>
using namespace std;
#define maxn 500005
int a[maxn];
int main(){
    int n,mx=0,in;
    scanf("%d",&n);
    for(int j=0;j<n;j++){
        scanf("%d",&a[j]);
        if(mx<a[j]){
            mx = a[j];
            in = j;
        }
    }
    string s="";
    int l = 0,r = n-1,k=-1;
    while(l<=r){
        if(k<min(a[l],a[r])){
            if(a[l]<a[r]){
                s+="L";
                k=a[l];
                l++;
            }else if(a[l]>a[r]){
                s+='R';
                k=a[r];
                r--;
            }else{
               int res1=0,x=k;
               int res2=0,y=k;
               for(int i = l;i<=in;i++){
                  if(a[i]>x){
                     x = a[i];
                     res1++;
                  }else break;
               }
               
               for(int i = r;i>=in;i--){
                  if(a[i]>y){
                     y = a[i];
                     res2++;
                  }else break;
               }
               if(res1>res2){
                   k = a[l];
                   l++;
                   s+='L';
               }else{
                   k = a[r];
                   r--;
                   s+='R';
               }
               
            }
        }else if(k<a[l]){
            s+='L';
            k = a[l];
            l++;
        }else if(k<a[r]){
            s+='R';
            k = a[r];
            r--;
        }else break;

    }
    cout<<s.size()<<endl;
    cout<<s<<endl;
}

 

D:N Problems During K Days

 

#include<bits/stdc++.h>
using namespace std;
#define maxn 500005
#define LL long long
LL a[maxn];
int main(){
   LL n,m;
   scanf("%lld%lld",&n,&m);for(int j=0;j<m;j++){
      a[j] = (n - (m - j) * (m - 1 -j) / 2) / (m-j);
      //cout<<a[j]<<endl;
      if(j>0&&a[j]>a[j-1]*2){
        a[j]=a[j-1]*2;
      }
      n-=a[j];
      if(n<0){
        cout<<"NO"<<endl;
        return 0;
      }
   }
    if(n){
        cout<<"NO"<<endl;
        return 0;
      
    }
   cout<<"YES"<<endl;
   for(int j=0;j<m;j++){
      cout<<a[j]<<" ";
   }
}

 

E:Minimum Array

#include<bits/stdc++.h>
using namespace std;
#define maxn 500005
#define LL long long
int a[maxn];
map<int,int>mp;
set<int>s;
vector<int>Q;
int main(){
   int n;
   cin>>n;
   for(int j=0;j<n;j++){
      cin>>a[j];
   }
   for(int j=0;j<n;j++){
       int x;
       cin>>x;
       mp[x]++;
       s.insert(x);
   }
   for(int j=0;j<n;j++){
      int x = (n-a[j])%n;
      set<int> ::iterator it = s.lower_bound(x);
      if(it==s.end()){
         it=s.begin();
      }
      if(mp[*it]>0){
         mp[*it]--;
         cout<<(*it+a[j])%n<<" ";
      }
      if(mp[*it]==0){
         s.erase(it);
      }

   }
}

 

F:Maximum Balanced Circle

#include<bits/stdc++.h>
using namespace std;
#define maxn 500005
#define LL long long
int a[maxn];
map<int,int>mp;
set<int>s;
vector<int>q,w;
int main(){
   int n;
   cin>>n;
   for(int j=0;j<n;j++){
     scanf("%d",&a[j]);
     mp[a[j]]++;
     q.push_back(a[j]);
   }
   sort(q.begin(),q.end());
   q.erase(unique(q.begin(),q.end()),q.end());
   int l =0,mx = 0,res = 0,r=-1;
   for(int j=0;j<q.size();j++){
      if(res==0){
         res+=mp[q[j]];
         if(res>mx){
            mx = res;
            r = j;
         }
      }else{
         if(q[j]==q[j-1]+1){
            if(mp[q[j]]>=2){
                res+=mp[q[j]];
                if(res>mx){
                    mx = res;
                    r = j;
                }
            }else{
                res+=mp[q[j]];
                if(res>mx){
                    mx = res;
                    r = j;
                }
                res = mp[q[j]];
            }
         }else{
            res=mp[q[j]];
            if(res>mx){
                mx = res;
                r = j;
            }
         }
      }
   }
//   if(mx==21){
//      cout<<q[r]<<endl;
//   }
//   cout<<mx<<" "<<r<<endl;
   int s = mp[q[r]];
   for(int j=r-1;j>=0;j--){

      if(q[j]+1!=q[j+1]){
         l=j+1;
         break;
      }else{
        s+=mp[q[j]];
        if(s==mx){
            l=j;
            break;
        }
      }
   }
//   cout<<l<<endl;
   for(int j=l;j<=r;j++){
      while(mp[q[j]]>1){
         w.push_back(q[j]);
         mp[q[j]]--;
      }
   }
   for(int j=r;j>=l;j--){
      w.push_back(q[j]);
   }
   cout<<w.size()<<endl;
   for(int j=0;j<w.size();j++){
      cout<<w[j]<<" ";
   }
}

 

 

转载于:https://www.cnblogs.com/DyLoder/p/10794457.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值