Educational Codeforces Round 93 (Rated for Div. 2)

A - Bad Triangle

选出三个序列使之不能组成三角形。先把差距最大的选了,枚举中间值。两边之和不大于第三边。

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#include<iostream>
#include<algorithm>
using namespace std;
const int N=50010;
int a[N];
int main()
{IO;int T;cin>>T;while(T--){int n;cin>>n;for(int i=1;i<=n;i++) cin>>a[i];int i;for(i=2;i<n;i++) if(a[1]+a[i]<=a[n])break;if(i==n) cout<<-1<<endl;else cout<<1<<' '<<i<<' '<<n<<endl;}return 0;
}

B - Substring Removal Game

第一次没加#include<vector>Compilation error了。。
考虑原串中连续的1。两人一定轮流选择目前连续1个数最多的。把连续的1个数存到一个数组,逆序。两人轮流取即可。

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=110;
int a[N];
int main()
{IO;int T;cin>>T;while(T--){string s;cin>>s;int n=s.size();vector<int> ans(n);for(int i=1;i<=n;i++) a[i]=s[i-1]-'0';for(int i=1;i<=n;i++){int j=i;while(j<=n&&a[i]==a[j]) j++;if(a[i]==1) ans.push_back(j-i);i=j-1;}int res=0;sort(ans.begin(),ans.end());reverse(ans.begin(),ans.end());for(int i=0;i<ans.size();i++) if(i%2==0) res+=ans[i];cout<<res<<endl;}return 0;
}

C - Good Subarrays

对于原数组a[l+1]+a[l+2]+⋯+a[r]=r−l+1a[l+1]+a[l+2]+\dots+a[r]=r-l+1a[l+1]+a[l+2]++a[r]=rl+1考虑前缀和数组即a[r]−a[l]=r−la[r]-a[l]=r-la[r]a[l]=rl变换一下a[r]−r=a[l]−la[r]-r=a[l]-la[r]r=a[l]l。因此只需统计a[i]−ia[i]-ia[i]i的个数,根据组合数的计算公式即可。由于可能有负数弄了个map映射。上述情况未考虑i=0的情况,因此最后应加上a[i]==i的个数。

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#include<cstdio>
#include<string>
#include<map>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=100010;
int a[N];
map<int,int> mp;
int idx=0;
int get(int s)
{if(!mp.count(s)) mp[s]=++idx;return mp[s];
}
ll cnt[N];
int main()
{IO;int T;cin>>T;while(T--){int n;cin>>n;mp.clear();for(int i=0;i<=n;i++) cnt[i]=0;idx=0;string s;cin>>s;for(int i=1;i<=n;i++) a[i]=s[i-1]-'0';for(int i=1;i<=n;i++) a[i]+=a[i-1];for(int i=1;i<=n;i++) cnt[get(a[i]-i)]++;ll res=0;for(int i=1;i<=idx;i++) res+=1ll*cnt[i]*(cnt[i]-1)/2;for(int i=1;i<=n;i++)if(a[i]==i) res++;cout<<res<<endl;}return 0;
}

这题很快就想到怎么写了,但是码代码能力还是不行写了半天。最开始没想用map弄明白数组开多大烦死了(负数可以平移)然后就用map了。看群里讨论发现负数不一定平移,可以为负数多开一个数组记录a[-i],i<0

D - Colored Rectangles

首先贪心,对于每一对木条,肯定选择长的。因此先降序排列数组。
f[i][j][k]表示:R用了i个,G用了j个,B用了k个的集合。转移考虑最后用的是那一对木棒。

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#include<cstdio>
#include<string>
#include<map>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=210;
int a[N],b[N],c[N];
int f[N][N][N];
int cnta,cntb,cntc;
int main()
{IO;cin>>cnta>>cntb>>cntc;for(int i=1;i<=cnta;i++) cin>>a[i];for(int i=1;i<=cntb;i++) cin>>b[i];for(int i=1;i<=cntc;i++) cin>>c[i];sort(a+1,a+1+cnta);sort(b+1,b+1+cntb);sort(c+1,c+1+cntc);reverse(a+1,a+1+cnta);reverse(b+1,b+1+cntb);reverse(c+1,c+1+cntc)for(int i=0;i<=cnta;i++)for(int j=0;j<=cntb;j++)for(int k=0;k<=cntc;k++){if(i&&j&&(i+j+k)%2==0) f[i][j][k]=max(f[i][j][k],f[i-1][j-1][k]+a[i]*b[j]);if(j&&k&&(i+j+k)%2==0) f[i][j][k]=max(f[i][j][k],f[i][j-1][k-1]+c[k]*b[j]);if(i&&k&&(i+j+k)%2==0) f[i][j][k]=max(f[i][j][k],f[i-1][j][k-1]+a[i]*c[k]);}int res=0;for(int i=0;i<=cnta;i++) res=max(res,f[i][cntb][cntc]);for(int i=0;i<=cntb;i++) res=max(res,f[cnta][i][cntc]);for(int i=0;i<=cntc;i++) res=max(res,f[cnta][cntb][i]);cout<<res<<endl;return 0;
}

D题最后1分钟提交的太惊险了。

E-Two Types of Spells

群里大佬说是权值线段树+离散化,这个我学过补一下吧。
如果有klightning,那么能过翻倍k-1或者k个伤害(讨论一下),翻倍肯定翻倍最大的几个,因此考虑权值线段树(因此需要离散化)维护前k大,一般有删除加入需要用set维护,数据无重复,让题目简单不少。
lower_bound只能够在升序情况下使用

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#include<cstdio>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=200010;
int n;
pii q[N];
vector<int> id;
struct node
{int l,r,cnt;ll sum;
}tree[N*4];
int get(int a)
{int l=0,r=id.size()-1;while(l<r){int mid=l+r>>1;if(id[mid]<=a) r=mid;else l=mid+1;}return l+1;
}
void pushup(int u)
{tree[u].cnt=tree[u<<1].cnt+tree[u<<1|1].cnt;tree[u].sum=tree[u<<1].sum+tree[u<<1|1].sum;}
void build(int u,int l,int r)
{tree[u]={l,r,0,0};if(l==r) return;int mid=l+r>>1;build(u<<1,l,mid),build(u<<1|1,mid+1,r);
}
void modify(int u,int k,int x)
{if(tree[u].l==tree[u].r){tree[u].cnt+=x;tree[u].sum+=x*id[k-1];return;}int mid=tree[u].l+tree[u].r>>1;if(k<=mid) modify(u<<1,k,x);else modify(u<<1|1,k,x);pushup(u);
}
ll query(int u,int k)
{if(tree[u].l==tree[u].r) return tree[u].sum;int tmp=tree[u<<1].cnt;if(tmp>=k) return query(u<<1,k);else return tree[u<<1].sum+query(u<<1|1,k-tmp);
}
int main()
{IO;cin>>n;build(1,1,n);for(int i=1;i<=n;i++){cin>>q[i].first>>q[i].second;id.push_back(abs(q[i].second));}sort(id.begin(),id.end());id.erase(unique(id.begin(),id.end()),id.end());reverse(id.begin(),id.end());set<int> fire,lightning;int k=0;ll res=0;for(int i=1;i<=n;i++){if(q[i].first==1){if(q[i].second>0){k++;lightning.insert(q[i].second);res+=q[i].second;modify(1,get(q[i].second),1);}else{k--;lightning.erase(-q[i].second);res+=q[i].second;modify(1,get(-q[i].second),-1);}}else{if(q[i].second>0){fire.insert(q[i].second);res+=q[i].second;modify(1,get(q[i].second),1);}else{fire.erase(-q[i].second);res+=q[i].second;modify(1,get(-q[i].second),-1);}}if(fire.empty()){if(k>1)cout<<res+query(1,k-1)<<'\n';else cout<<res<<'\n';}else if(lightning.empty()) cout<<res<<'\n';else{int minl=*lightning.begin();auto t=fire.end();t--;int maxf=*t;if(minl>maxf){if(k>1) cout<<res+query(1,k-1)+maxf<<'\n';else cout<<res+maxf<<'\n';}else{if(k>0) cout<<res+query(1,k)<<'\n';else cout<<res<<'\n';}}}return 0;
}

要加油哦~

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/319672.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

P4198-楼房重建【线段树】

正题 题目链接:https://www.luogu.com.cn/problem/P4198 题目大意 nnn条线&#xff0c;开始时第iii条是(i,0)(i,0)(i,0)的一个点。 每次有操作把第xxx条线变成(x,0)(x,0)(x,0)到(x,y)(x,y)(x,y)。然后求从(0,0)(0,0)(0,0)能看到几条线。 解题思路 把线变成斜率的话就是对于每…

2020牛客暑期多校训练营(第四场)

2020牛客暑期多校训练营&#xff08;第四场&#xff09; 这场属实有点难受 文章目录A Ancient DistanceB Basic Gcd Problem题目代码&#xff1a;C Count New StringD Dividing StringsE EliminateF Finding the Order题意&#xff1a;题解&#xff1a;代码&#xff1a;G Geome…

《C# 程序员的自我修养》送书活动结果公布

截止到9月28日24&#xff1a;00 &#xff0c;本次送书活动《C# 程序员的自我修养》共收到150多位同学参与回复。以下5位同学将获赠书籍一本&#xff1a;夏树、Damon、水墨清华、天天、kang以上同学请加小二微信领取赠书小二微信&#xff1a;geffzhang.NET社区新闻&#xff0c;深…

【AC自动机】单词(luogu 3966/ybtoj AC自动机-2)

正题 luogu 3966 ybtoj AC自动机-2 题目大意 给你n个单词&#xff0c;让你查询这写单词分别在这n个单词中出现过多少次 解题思路 先用AC自动机建好图&#xff0c;然后每个点的权值为1&#xff0c;然后向nx传递 代码 #include<cstdio> #include<cstring> #inclu…

AtCoder Beginner Contest 175总结

这次做了ABCE~ A - Rainy Season 懒得想直接分类讨论 #define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0) #include<string> #include<iostream> using namespace std; int main() {string s;cin>>s;int res0;if(s[0]R&&s[1]R&&a…

P5607-[Ynoi2013]无力回天NOI2017【线性基,线段树,树状数组】

正题 题目链接:https://www.luogu.com.cn/problem/P5607 题目大意 nnn个数字的序列&#xff0c;mmm次操作 区间[l,r][l,r][l,r]异或上一个值vvv询问区间[l,r][l,r][l,r]中选出一些数来异或的最大异或和 解题思路 最大异或和的话只能是线性基了&#xff0c;但是线性基的区间修…

牛客算法周周练15

牛客算法周周练15 文章目录A 数列下标B 可持久化动态图上树状数组维护01背包C 璀璨光滑D 树上求和E 算式子A 数列下标 题意很明确&#xff0c;再看看数据&#xff0c;所以我们直接两重循环&#xff0c;用数组b来记录右边第一个大的数的下标 代码&#xff1a; #include<bit…

使用 dotTrace 分析 .NET Core 代码问题

0.背景在项目开发之中&#xff0c;前期可能主要以保证任务完成为主&#xff0c;对于性能优化主要在于开发完成之后再来进行。可能在测试的时候发现部分接口的代码执行时间过长&#xff0c;但是又毫无头绪&#xff0c;这个时候你就需要性能分析工具来协助你排查问题了。常规性能…

【AC自动机】前缀匹配(ybtoj AC自动机-3)

正题 ybtoj AC自动机-3 题目大意 给你一个字符串和若干匹配串&#xff0c;问你匹配串的前缀和字符串的最大匹配 解题思路 先把所有匹配串丢进AC自动机&#xff0c;然后拿字符串去跑 每次只在当前位置存下贡献&#xff0c;然后按bfs的倒叙传递贡献&#xff0c;最后再倒着跑每…

Codeforces Global Round 10

这种大场全是神仙打架&#xff0c;向我这种菜菜就是掉分www太难了 神仙打架&#xff0c;百姓遭殃。 A - Omkar and Password 分析可以知道&#xff0c;只要数组元素不是全部相等答案就是1&#xff0c;如何数组元素全部相等答案就是n。 #define IO ios::sync_with_stdio(fals…

【每日一题】7月17日题目精讲—BOWL 碗的叠放

【每日一题】7月17日题目精讲—BOWL 碗的叠放 时间限制&#xff1a;C/C 1秒&#xff0c;其他语言2秒 空间限制&#xff1a;C/C 262144K&#xff0c;其他语言524288K 64bit IO Format: %lld题目描述 小H有n个碗需要放进橱柜&#xff0c;她希望将他们叠起来放置。你知道每个碗都…

基于Ocelot的gRpcHttp网关

什么是gRpcHttp网关通俗的讲就是将gRpc提供的服务以rest api的形式提供出去&#xff0c;不需要再单独的写一个webapi去做这件事。gRpcHttp网关好处减少不必要代码&#xff0c;减少中间层提高通讯效率。以前可能是这样用了gRpc网关后是这样gRpcHttp网关提供哪些功能可以直接加载…

CF917D-Stranger Trees【矩阵树定理,高斯消元】

正题 题目链接:https://www.luogu.com.cn/problem/CF917D 题目大意 给出nnn个点的一棵树&#xff0c;对于每个kkk求有多少个nnn个点的树满足与给出的树恰好有kkk条边重合。 解题思路 矩阵树有一个统计所有树边权和的和用法&#xff0c;就是把变量变成一个形如wx1wx1wx1的多项…

【AC自动机】屏蔽词删除(ybtoj AC自动机-4)

正题 ybtoj AC自动机-4 题目大意 有一个字符串和若干要删除的串&#xff08;不存在包含关系&#xff09;&#xff0c;每次从前往后搜&#xff0c;搜到第一个要删除的串然后删掉&#xff0c;再从0开始搜 问你最后得到的字符串 解题思路 先把所有删除串丢进AC自动机中&#x…

Codeforces Round #665 (Div. 2)

2020/8/21 晚上打完球就22:10了&#xff0c;愣是没报上名&#xff08;cf打不开&#xff0c;然后就做了一下赛后交的过了3个题 A - Distance and Axis 数学题分类讨论一下即可 #define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0) #pragma GCC optimize(2) #inclu…

【每日一题】7月20日题目精讲—着色方案

来源&#xff1a;牛客网&#xff1a; 文章目录题目描述题解&#xff1a;代码&#xff1a;时间限制&#xff1a;C/C 1秒&#xff0c;其他语言2秒 空间限制&#xff1a;C/C 262144K&#xff0c;其他语言524288K 64bit IO Format: %lld题目描述 有n个木块排成一行&#xff0c;从左…

COSCon'18 面向全宇宙招募志愿者啦!

2018 中国开源年会&#xff08;COSCon18-China Open Source Conference 2018) 志愿者招募工作今日正式启动&#xff01;我们诚挚地欢迎开源社区的朋友们及高校的同学们加入志愿工作者团队&#xff0c;与国内外众多开源项目基金会、公司、大神等齐聚一堂&#xff0c;共襄盛举。招…

CF346E-Doodle Jump【类欧】

正题 题目链接:https://www.luogu.com.cn/problem/CF346E 题目大意 给出a,n,p,ha,n,p,ha,n,p,h&#xff0c;在每个ax%p(x∈[0,n])ax\%p(x\in[0,n])ax%p(x∈[0,n])的位置有一个关键点&#xff0c;询问是否所有相邻关键点之间的距离都不超过hhh。 解题思路 没怎么写过类欧&…

【AC自动机】病毒代码(ybtoj AC自动机-5)

正题 ybtoj AC自动机-5 题目大意 给出若干段01串&#xff0c;问你是否存在一个无限的01串&#xff0c;使得串中不存在给出的01串 解题思路 可以把给出01串用AC自动机处理&#xff0c;然后对每个01串的最后一位打上标记 根据AC自动机的连边性质&#xff08;即若无该边&#…

AtCoder Beginner Contest 176总结

由于打球又鸽了一场&#xff0c;快开学了好好打球&#xff01;&#xff01;&#xff01;&#xff08;狗头 还是补一补 A - Takoyaki 签到题 #define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0) #pragma GCC optimize(2) #include<iostream> #include<a…