Educational Codeforces Round 96 (Rated for Div. 2)

今天先补了上一场的Codeforces Global Round 11三道题,做的心神恍惚,然后17点报名没敢提交,先写了4个题剩下的改天补一补
我是真的服信号,卷积卷si我了

A - Number of Apartments

枚举3和5的个数,直接算出来7的个数即可

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=100010;
int main()
{IO;int T=1;cin>>T;while(T--){int n;cin>>n;bool ok=0;for(int i=0;i<=n;i++){if(ok) break;for(int j=0;j<=n;j++){int k=n-3*i-5*j;if(k<0||k%7) continue;cout<<i<<' '<<j<<' '<<k/7<<'\n';ok=1;break;}}if(!ok) cout<<-1<<'\n'; }return 0;}

B - Barrels

很明显需要把第2~k+1大的全部导入最大的容器中,然后求个和即是答案


#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=200010;
int n,k;
int a[N];
int main()
{IO;int T=1;cin>>T;while(T--){cin>>n>>k;for(int i=1;i<=n;i++) cin>>a[i];sort(a+1,a+1+n);reverse(a+1,a+1+n);ll res=0;for(int i=1;i<=k;i++) res+=a[i+1];res+=a[1];cout<<res<<'\n';}return 0;}

C - Numbers on Whiteboard

贪心:1一定最后再用,然后依次用两个最大的即可。
总的来说就是每次用两个最大的。


#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=200010;
int n,k;
int a[N];
int main()
{IO;int T=1;cin>>T;while(T--){cin>>n;vector<pii> ans;int now=n;for(int i=1;i<n;i++){ans.push_back({n-i,now});now=(n-i+now+1)/2;}cout<<now<<'\n';for(auto t:ans) cout<<t.first<<' '<<t.second<<'\n';cout<<'\n';}return 0;}

D - String Deletion

首先扫一遍序列,把相同的分段用一个vector存下来,不难发现我如果当前的一段个数大于1我们只需要两次操作都在这一段即可,否则只需要在后面的段中选择一个个数大于1的用操作1即可,简单模拟。

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=200010;
int n,k;
char s[N];
int main()
{IO;int T=1;cin>>T;while(T--){cin>>n;cin>>s+1;vector<int> now;for(int i=1;i<=n;i++){int j=i+1;while(j<=n&&s[i]==s[j]) j++;now.push_back(j-i);i=j-1;}int res=0;for(int i=0,j=0;i<now.size();i++){if(now[i]>=2){res++;continue;}bool ok=0;j=max(j,i+1);for(;j<now.size();j++){if(now[j]>=2) {now[j]--;ok=1;break;}}if(!ok) i++;res++;}cout<<res<<'\n';}return 0;
}

E - String Reversal

不难贪心出结论即:每次选择离自己最近的字母交换

首先可以记下每个字母出现的位置用26个vector即可,用树状数组快速求出每次移动需要的代价然后就不难得出答案了。


#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=200010;
char s[N],p[N];
int n;
queue<int> mp[27];
int tree[N];
int lowbit(int x)
{return x&-x;
}
void update(int k,int x)
{for(;k<=n;k+=lowbit(k)) tree[k]+=x;
}
int query(int k)
{int res=0;for(;k;k-=lowbit(k)) res+=tree[k];return res;
}
int main()
{IO;int T=1;//cin>>T;while(T--){cin>>n;cin>>s+1;for(int i=1;i<=n;i++){mp[s[i]-'a'].push(i);update(i,1);}ll res=0;for(int i=n;i;i--)//逆序字符{int pos=mp[s[i]-'a'].front();mp[s[i]-'a'].pop();res+=query(pos)-1;update(pos,-1);}cout<<res<<'\n';}return 0;}

我是刚刚做完信号的一题来写的题解,现在心态非常爆炸。。。
题解质量不想说了真的laji

剩下的题明天补一下吧(明天信号又要自己看书了,老师讲的根本听不懂啊啊啊)
要加哟哦~~

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

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

相关文章

【kruskal重构树】【主席树】werewolf 狼人(P4899)

正题 P4899 题目大意 给你一个图&#xff0c;对于每次询问Si,Ei,Li,RiS_i,E_i,L_i,R_iSi​,Ei​,Li​,Ri​&#xff0c;回答从SiS_iSi​走到EiE_iEi​&#xff0c;是否存在路径满足前面一段只经过Li∼n−1L_i\sim n-1Li​∼n−1,后面一段只经过0∼Ri0\sim R_i0∼Ri​ 解题思路…

数据结构题

来源&#xff1a;牛客网&#xff1a; 题目描述 题目背景 把一张纸对折100次就和珠穆朗玛峰一样高了哦 ——syh 题目描述 注:本系列题不按难度排序哦 输入描述: 第一行一个n,m 接下来一行n个数表示a[i] 接下来m行&#xff0c;每行l,r,l1,r1,x&#xff0c;表示求get(l,r,x)…

YbtOJ#832-鸽子饲养【凸包,Floyd】

正题 题目链接:https://www.ybtoj.com.cn/contest/116/problem/3 题目大意 给出两个大小分别为n,mn,mn,m的点集A,BA,BA,B。 求出BBB的一个最小子集使得该子集的凸包包含了所有点集AAA中的点。 无解输出−1-1−1 2≤n≤105,3≤m≤5002\leq n\leq 10^5,3\leq m\leq 5002≤n≤…

Codeforces Global Round 11——E随机+线性基待补

A - Avoiding Zero 不难发现如果数组所有元素和为0一定不能满足条件&#xff0c;否则一定能满足。 假设所有元素和不为0尝试以下构造&#xff0c;如果正数和小于负数和的绝对值&#xff0c;那么逆序排列&#xff0c;否则顺序排列&#xff0c;这样一定满足题意。 #define IO i…

声明式RESTful客户端在asp.net core中的应用

1 声明式RESTful客户端声明式服务调用的客户端&#xff0c;常见有安卓的Retrofit、SpringCloud的Feign等&#xff0c;.net有Refit和WebApiClient&#xff0c;这些客户端都是以java或.net某个语言来声明接口&#xff0c;描述如何请求RESTful api。1.1 WebApiClientWebApiClient由…

【树链剖分】LCA(P4211)

正题 P4211 题目大意 给你一棵树&#xff0c;有m次询问&#xff0c;每次询问要回答∑ilrdep[lca(x,i)]\sum_{il}^rdep[lca(x,i)]∑ilr​dep[lca(x,i)] 解题思路 把用差分把问题分开&#xff0c;离线做 考虑树链剖分&#xff0c;对于每个点维护轻儿子的贡献&#xff0c;即轻…

洛谷 P1903 [国家集训队]数颜色 / 维护队列

题目描述 墨墨购买了一套N支彩色画笔&#xff08;其中有些颜色可能相同&#xff09;&#xff0c;摆成一排&#xff0c;你需要回答墨墨的提问。墨墨会向你发布如下指令&#xff1a; 1、 Q L R代表询问你从第L支画笔到第R支画笔中共有几种不同颜色的画笔。 2、 R P Col 把第P支画…

CF605E-Intergalaxy Trips【期望dp】

正题 题目链接:https://www.luogu.com.cn/problem/CF605E 题目大意 给出nnn个点的一张完全有向图&#xff0c;每一天iii到jjj的路径有pi,jp_{i,j}pi,j​的概率出现。 询问从111出发走到nnn在最优策略下的期望天数。 1≤n≤103,pi,i11\leq n\leq 10^3,p_{i,i}11≤n≤103,pi,i​…

常见形式 Web API 的简单分类总结

一、请求--响应API请求--响应类的API的典型做法是&#xff0c;通过基于HTTP的Web服务器暴露一个/套接口。API定义一些端点&#xff0c;客户端发送数据的请求到这些端点&#xff0c;Web服务器处理这些请求&#xff0c;然后返回响应。响应的格式通常是JSON或XML。在这种类型的Web…

复读数组(nowcoder 1103A)

正题 nowcoder 1103A 题目大意 有一个数组&#xff0c;将其复制k遍&#xff0c;求所有区间内不同元素个数的和 解题思路 同一个区间内有相同的数那么在最右边的数计算贡献 记 rrr 为右边第一个相等的数&#xff0c;那么贡献就是到 rrr 的距离乘上左边的数字个数&#xff08…

新疆大学ACM新生赛(公开赛)

A~D签到题&#xff0c;E稍微用点脑子?F经典分治题&#xff08;lyd蓝书的袭击&#xff09;反正分治算就行了复杂度2个log&#xff08;用个归并能到1个log&#xff09; A - hello world #define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0) #pragma GCC optimize(2…

P3214-[HNOI2011]卡农【dp】

正题 题目链接:https://www.luogu.com.cn/problem/P3214 题目大意 一个由1∼n1\sim n1∼n的所有整数构成的集合SSS&#xff0c;求出它的mmm个不同非空子集满足每个元素都出现了偶数次。 解题思路 集合的话不用考虑顺序&#xff0c;可以输出有序的答案除以m!m!m!就好了。 选…

Graph Coloring I

来源&#xff1a;牛客网&#xff1a; 题目描述 修修在黑板上画了一些无向连通图&#xff0c;他发现他可以将这些图的结点用两种颜色染色&#xff0c;满足相邻点不同色。 澜澜不服气&#xff0c;在黑板上画了一个三个点的完全图。修修跟澜澜说&#xff0c;这个图我能找到一个简…

Visual Studio 2017 15.9预览版3支持ARM64 for UWP

微软针对Visual Studio 2017 15.9的更新工作还在继续。在15.9的第三个预览版中&#xff0c;微软宣布支持ARM64平台上的UWP应用程序&#xff0c;并扩展了TypeScript开发人员可以使用的功能。和通常的情况一样&#xff0c;该版本还包含了大量的修复程序。UWP应用现在可以把ARM64平…

【树形DP】路径计数机(nowcoder 1103-B)

正题 nowcoder 1103-B 题目大意 给你一棵树&#xff0c;让你找两条不交的链&#xff0c;长度分别为a,b&#xff0c;问有多少中方案 解题思路 设fx,0∼3,yf_{x,0\sim 3,y}fx,0∼3,y​为在x的子树中&#xff0c;第1/2条链连了y条边&#xff0c;另一条链连完了/没连 然后对于每…

[ZJOI2007]矩阵游戏

来源&#xff1a;牛客网&#xff1a; 题目描述 小Q是一个非常聪明的孩子&#xff0c;除了国际象棋&#xff0c;他还很喜欢玩一个电脑益智游戏——矩阵游戏。矩阵游戏在一个N *N黑白方阵进行&#xff08;如同国际象棋一般&#xff0c;只是颜色是随意的&#xff09;。 每次可以对…

HHKB Programming Contest 2020 总结

A - Keyboard 签到题1 #define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0) #pragma GCC optimize(2) #include<set> #include<map> #include<cmath> #include<queue> #include<string> #include<vector> #include<cstdio…

AT4996-[AGC034F]RNG and XOR【FWT,生成函数】

正题 题目链接:https://www.luogu.com.cn/problem/AT4996 题目大意 给出一个0∼2n−10\sim 2^n-10∼2n−1下标的数组ppp&#xff0c;pip_ipi​表示有pip_ipi​的权重概率选择iii。 开始有一个x0x0x0&#xff0c;每次选择一个数字yyy让xxxoryxx\ xor\ yxx xor y 对于每个iii…

如何通过本地化事件正确实现微服务内部强一致性,事件总线跨微服务间最终一致性...

目录设计重点流程图伪代码2.1. PublishEvent2.2. SubscribeEvent2.3. Publisher2.4. Subscriber微服务 强一致性3.1 Publisher3.2 Subscriber事件总线 - 跨服务 最终一致性4.1 Publisher & Subscriber 都开启了本地事务&#xff0c;保证了强一致性4.2 问题场景一&#xff1…

【状压DP】十二桥问题(nowcoder 1104-B)

正题 nowcoder 1104-B 题目大意 给你一个无向图&#xff0c;问你从1开始经过若干必要边&#xff0c;然后回到1的最短路径 解题思路 因为关键边较少&#xff0c;先从每个关键点跑一遍dij&#xff0c;得出最短距离 设fs,if_{s,i}fs,i​表示必要边的状态为s&#xff0c;当前在…