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

Codeforces Round #555 (Div. 3) c2 d e f相关推荐

  1. Codeforces Round # 555 (Div. 3) C2. Increasing subsequence (complicated version) (贪心)

    题目链接:http://codeforces.com/contest/1157/problem/C2 当左右两边数字相同时,需要判断一下取哪边能得到更长的递增序列 #include <iostr ...

  2. Codeforces Round #568 (Div. 2)C2. Exam in BerSU (hard version)

    Codeforces Round #568 (Div. 2)C2. Exam in BerSU (hard version) 贪心+暴力 大致题意:N个人考试,每个人花费的时间是a[i],他们总共花费 ...

  3. Codeforces Round #555 (Div. 3), problem: (C2) Increasing Subsequence (hard version)【贪心+撞到南墙也不回头】

    题目链接 题目大意 复杂版大意是我们可以从左右两端每次拿走一个数,一直拿,不过要满足一个条件,每次拿的数要保证严格递增(即从小到大然后不会有相同的情况) 复杂版的话是会有相同的数字出现 在题解中正式说 ...

  4. Codeforces Round #555 (Div. 3) AB

    A:    http://codeforces.com/contest/1157/problem/A 题意:每次加到10的整数倍之后,去掉后面的0,问最多有多少种可能. 1 #include < ...

  5. 差分 ---- Codeforces Round #672 (Div. 2):C2. Pokémon Army (hard version)[差分的思想]

    题目链接 题目大意:就算给你一序列,按照顺序出若干个数组成一个的序列,然后对这个序列定义一个权值就算奇数位置的和减去偶数位置的和,问你能的到的最大的权值是多少? **a1 - a2 + a3 - a4 ...

  6. Codeforces Round #672 (Div. 2) C2 - Pokémon Army (hard version)(贪心,维护变化值)

    x数组里选一个子数组y(原数组顺序),y1-y2+y3-y4+- 的最大值 然后还有q次交换操作,每次修改之后都要输出新的最大值 (1)如果没有修改,单纯对于当前数组考虑,我们最后选出来的点肯定是波峰 ...

  7. Codeforces Round #552 (Div. 3) E stl模拟 F dp G gcd

    contest链接 https://codeforces.com/contest/1154 E 题解思路 直接哈希模拟删除T了,可以用setsetset和lowerlowerlower_boundbo ...

  8. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  9. Codeforces Round #694 (Div. 1 + Div2)(A ~ H,8题全,超高质量题解)【每日亿题】2021/2/1、2/2

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 [每日亿题]Codeforces Round #694 (Div. 1 + Div2)(A ~ ...

最新文章

  1. 用了5年的旧笔记本不要丢,1/4新机价格升级机器学习战斗本,隔壁研究员都馋哭了...
  2. ****** 三十五 ******、软设笔记【网络基础】-安全性、可靠性与系统性能评测-数据安全与保密...
  3. 如何把二进制数化成十进制数_二进制数按位进行逻辑运算
  4. 『设计模式』写代码偷懒小技巧,程序开发大智慧--享元模式
  5. apt-get 与 apt-cache使用
  6. opc怎么在计算机上测试,OPC测试
  7. public 返回一数组_数组:滑动窗口拯救了你
  8. 【转】如何读一篇论文
  9. java 4级_《软件测试人员(Java)(4级)》【价格 目录 书评 正版】_中国图书网
  10. CSS3过渡详解-遁地龙卷风
  11. Java之路:你真的了解final吗?
  12. CSS+DIV实现圆角
  13. 左耳朵耗子:疫情下的远程办公,聊聊我的经验和实践
  14. 【毕业设计】深度学习 python opencv 火焰检测识别
  15. 直播回顾 丨TBase多中心多活与高可用方案实践
  16. 【OSS】使用Element实现图片上传到OSS
  17. linux如何新增dwployop用户,Linux(Centos)快速搭建SVN
  18. 深度势能 deep potential
  19. Android 8.0 Activity启动流程分析
  20. python1加到100_python for循环1加到100的和

热门文章

  1. zabbix安装使用及监控案例(从头到尾)
  2. mysql 修改表结构提示 MySQL said: Table is read only
  3. photoshop给绘制的形状使用渐变工具
  4. Synchronized 天天用,实现原理你懂吗?
  5. 阿里开源那个牛哄哄问题排查工具竟然不会用?最佳实践来了!
  6. 打破你的认知,数字除以 0 一定会崩溃吗?
  7. Hutool Java 工具类库导出 Excel,超级简单!
  8. 单日2000W+订单,如何忙中不错?美团外卖业务异常检测实践详解
  9. 如何快速上手一款开源软件
  10. 多线程:线程之间的协作(join、wait、notify、notifyAll、await、signal、signalAll)