Educational Codeforces Round 178 div2(题解ABCDE)

A. Three Decks

#1.由于最后三个数会相等,提前算出来和,%3判断,再判前两个数是否大于

#include<iostream>
#include<vector>
#include<stdio.h>
#include<map>
#include<string>
#include<algorithm>
#include<queue>
#include<cstring>
#include<stack>
#include<array>
#include<cmath>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include<iomanip>
using namespace std;
using ll = long long;
using llu = unsigned long long;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
const ll MIN = -9187201950435737472ll;
ll mod = 1e9 + 7;
ll base = 131;
const int N = 1e4 + 10;
void solve()
{int a,b,c;cin>>a>>b>>c;if((a+b+c)%3==0){int tmp=(a+b+c)/3;if((a<=tmp)&&(b<=tmp))cout<<"YES"<<endl;else cout<<"NO"<<endl;}else cout<<"NO"<<endl;
}
int main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);int t = 1;cin>>t;while (t--){solve();}return 0;
}

B. Move to the End

我们每次要从数组末尾拿1,2,3...一直到n 个数,对于每次取,我都可以拿一个数到数组末尾。

#1.为此我们可以取一个前缀max数组,讨论从后向前的k个元素的前缀max是否大于这个元素

#include<iostream>
#include<vector>
#include<stdio.h>
#include<map>
#include<string>
#include<algorithm>
#include<queue>
#include<cstring>
#include<stack>
#include<array>
#include<cmath>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include<iomanip>
using namespace std;
using ll = long long;
using llu = unsigned long long;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
const ll MIN = -9187201950435737472ll;
ll mod = 1e9 + 7;
ll base = 131;
const int N = 1e4 + 10;
void solve()
{int n;cin>>n;vector<ll>a(n+1);vector<ll>pre(n+1,0);for(int i=1;i<=n;i++){cin>>a[i];pre[i]=max(pre[i-1],a[i]);}ll sum=0;for(int i=n;i>=1;i--){sum+=a[i];if(pre[i-1]>a[i])cout<<sum-a[i]+pre[i-1]<<" ";else cout<<sum<<" ";}cout<<endl;
}
int main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);int t = 1;cin>>t;while (t--){solve();}return 0;
}

C. Card Game

有n张卡,编号大的克制编号小的,特别的1克制n,每回合Alice先出,Bob后手,如Alice克制Bob则得Alice得这两张牌,反之Bob

#1.注意到由于Alice先手,只有无论Alice出任何牌Bob都能克制她时,Bob胜,其余情况Alice胜

#2.可以用vector存Alice的牌,set存Bob的牌,二分+特判

#include<iostream>
#include<vector>
#include<stdio.h>
#include<map>
#include<string>
#include<algorithm>
#include<queue>
#include<cstring>
#include<stack>
#include<array>
#include<cmath>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include<iomanip>
using namespace std;
using ll = long long;
using llu = unsigned long long;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
const ll MIN = -9187201950435737472ll;
ll mod = 1e9 + 7;
ll base = 131;
const int N = 1e4 + 10;
void solve()
{int n;cin>>n;string s;cin>>s;vector<int>a;s="#"+s;set<int>st;bool tag=true;for(int i=1;i<=n;i++){if(s[i]=='A')a.push_back(i);else st.insert(i);}int l=a.size();for(int i=0;i<l;i++){if(a[i]==n){if(!(st.count(1)))tag=false;}else{auto it=st.upper_bound(a[i]);if(a[i]==1){if(*it==n)tag=false;}else{if(*it<a[i])tag=false;}}}if(tag)cout<<"Bob"<<endl;else cout<<"Alice"<<endl;
}
int main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);int t = 1;cin>>t;while (t--){solve();}return 0;
}

D. Array and GCD

给一个长为n的数组a,可以让数组中的任一元素减1,另一元素加1,也可只减不加,最后问最少删几个元素能让数组任意两个元素之间互质,(删元素要在操作之前),并且要保证操作后的数组中任意元素都是>=2的

#1. 要让任意两个元素之间互素,当数组中都是素数即可

#2.再来考虑操作,我能让数组中任意元素变化,但数组的总和只能是不变或变小的,假设剩了x个元素,它最小应该是前x个素数相加。

#3.到这只需用欧拉筛筛到1e7(大概6e5个素数),在对素数做前缀和,即为保留i个元素,i个元素的总和至少为多少

#4.保持贪心性质,删数只删最小的

#include<iostream>
#include<vector>
#include<stdio.h>
#include<map>
#include<string>
#include<algorithm>
#include<queue>
#include<cstring>
#include<stack>
#include<array>
#include<cmath>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include<iomanip>
using namespace std;
using ll = long long;
using llu = unsigned long long;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
const ll MIN = -9187201950435737472ll;
ll mod = 1e9 + 7;
ll base = 131;
const int N = 1e7 + 10;
const int M=1e6+4;
bool vis[N];
vector<int>primes;
ll pre[M];
void init(int x)
{vis[0]=vis[1]=true;for(int i=2;i<=x;i++){if(!vis[i])primes.push_back(i);int l=primes.size();for(int j=0;j<l&&primes[j]*i<=x;j++){vis[i*primes[j]]=true;if(i%primes[j]==0)break;}}
}
void solve()
{int n;cin>>n;vector<int>a(n+1);ll sum=0;for(int i=1;i<=n;i++)cin>>a[i],sum+=a[i];sort(a.begin()+1,a.end(),greater<int>());if(n<2){cout<<0<<endl;return;}for(int i=n;i>=2;i--){if(sum>=pre[i]){cout<<n-i<<endl;return;}sum-=a[i];}cout<<n-1<<endl;
}
int main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);int t = 1;cin>>t;init(1e7);int l=primes.size();//cout<<l<<endl;for(int i=0;i<l;i++){pre[i+1]=pre[i]+primes[i];}while (t--){solve();}return 0;
}

E. Unpleasant Strings

给一个长为n的字符串s,其中只能出现26个字母前k个字母,q次询问,每次询问给一个字符串,对于每次询问给出至少添加几个字母能使它不为s的子序列。

#1.对于本就不是它的子序列的字符串,添加0个。那就需要判断以一个字符串是否为另一个字符串的子序列。k很小,可以将每种字符用vector存起来,在判断时,只需要遍历要判断的字符串,二分对于这个字符出现序列中第一个大于上一个位置的位置

#2.通过上述方法可以找到这个字符串作为子序列第一个末尾,对于后续元素至少要添加的元素数量,我们可以采用后缀和提前预处理出答案,后缀和是从后向前遍历,将k个元素都出现的一段视作1,再做后缀和

#include<iostream>
#include<vector>
#include<stdio.h>
#include<map>
#include<string>
#include<algorithm>
#include<queue>
#include<cstring>
#include<stack>
#include<array>
#include<cmath>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include<iomanip>
using namespace std;
using ll = long long;
using llu = unsigned long long;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
const ll MIN = -9187201950435737472ll;
ll mod = 1e9 + 7;
ll base = 131;
const int N = 1e4 + 10;
int main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);int l,q,k;cin>>l>>k;string s;cin>>s;string str;vector<vector<int>>dp(k+1,vector<int>());vector<ll>suf(l+3,0);s="#"+s;for(int i=1;i<=l;i++){dp[s[i]-'a'+1].push_back(i);}suf[l]=0;int cnt=0;vector<bool>vis(k+1,false);for(int i=l-1;i>=0;i--){if(!vis[s[i+1]-'a'+1])cnt++,vis[s[i+1]-'a'+1]=true;suf[i]=suf[i+1]+(cnt==k);if(cnt==k){fill(vis.begin(),vis.end(),false);cnt=0;}}cin>>q;while(q--){cin>>str;int len=str.length();int pos=-1;bool tag=true;for(int i=0;i<len;i++){int x=str[i]-'a'+1;auto tmp=upper_bound(dp[x].begin(),dp[x].end(),pos);//cout<<tmp<<endl;if(tmp==dp[x].end()){tag=false;break;}pos=*tmp;//cout<<pos<<endl;}if(!tag){cout<<0<<endl;continue;}//cout<<pos<<endl;cout<<suf[pos]+1<<endl;}return 0;
}

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

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

相关文章

如何创建一个导入模板?全流程图文解析

先去找到系统内可以上传东西的按钮 把你的模板上传上去,找到对应的fileName 图里的文字写错了,是复制粘贴"filePath"到URL才能下载

通信原理第七版与第六版区别附pdf

介绍 我用夸克网盘分享了「通信原理 第7版》樊昌信」&#xff0c;链接&#xff1a;https://pan.quark.cn/s/be7c5af4cdce 《通信原理&#xff08;第7版&#xff09;》是在第6版的基础上&#xff0c;为了适应当前通信技术发展和教学需求&#xff0c;并吸取了数十所院校教师的反…

Mysql唯一性约束

唯一性约束&#xff08;Unique Constraint&#xff09;是数据库设计中用于保证表中某一列或多列组合的值具有唯一性的一种规则。它可以防止在指定列中插入重复的数据&#xff0c;有助于维护数据的完整性和准确性。下面从几个方面为你详细解释 作用 确保数据准确性&#xff1a…

测试基础笔记第十六天

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 一、UI自动化介绍1.认识UI自动化测试2.实施UI自动化测试前置条件3.UI自动化测试执行时机4.UI自动化测试核心作用和劣势 二、认识Web自动化测试工具-Selenium021.Sel…

PaddleX的安装

参考&#xff1a;安装PaddlePaddle - PaddleX 文档 1、安装PaddlePaddle 查看 docker 版本 docker --version 若您通过 Docker 安装&#xff0c;请参考下述命令&#xff0c;使用飞桨框架官方 Docker 镜像&#xff0c;创建一个名为 paddlex 的容器&#xff0c;并将当前工作目…

长效住宅IP是什么?如何获取长效住宅IP?

在当今的互联网世界里&#xff0c;IP地址作为连接用户与网站之间的桥梁&#xff0c;其重要性不言而喻。对于跨境电商、社交媒体运营以及数据采集等领域的专业人士而言&#xff0c;普通的IP地址已无法满足日益复杂的需求。他们更需要一种稳定、安全且持久的长效住宅IP来完成各类…

02 业务流程架构

业务流程架构提供了自上而下的组织鸟瞰图&#xff0c;是业务流程的全景图。根据所采用的方法不同&#xff0c;有时被称为流程全景图或高层级流程图&#xff0c;提供了业务运营中所有业务流程的整体视图。 这样有助于理解企业内部各个业务流程之间的相互关系以及它们如何共同工…

jenkins slave节点打包报错Failed to create a temp file on

jenkins slave节点打包报错 一、报错信息 FATAL: Unable to produce a script file Also: hudson.remoting.Channel$CallSiteStackTrace: Remote call to slave-83at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1784)at hudson.remoting.UserRequest$…

什么是 Swagger 以及如何在 Spring Boot 中实现 Swagger:配置与实践指南

在现代 RESTful API 开发中&#xff0c;Swagger 是一种广泛使用的工具&#xff0c;用于生成、描述和可视化 API 文档。它极大地简化了 API 的开发、测试和维护过程。结合 Spring Boot&#xff0c;Swagger 可以快速集成到项目中&#xff0c;生成交互式 API 文档&#xff0c;方便…

Xilinx FPGA支持的FLASH型号汇总

以博主这些年的FPGA开发使用经验来看&#xff0c;FPGA开发的主流还是以Xilinx FPGA为主&#xff0c;贸易战关税战打了这么多年&#xff0c;我们做研发的也不可避免的要涉及一些国产替代的工作&#xff1b;这里把Xilinx FPGA官方支持的各类&#xff08;国产和非国产&#xff09;…

第3讲:ggplot2完美入门与美化细节打磨——从基础绘制到专业级润色

目录 1. 为什么选择ggplot2? 2. 快速了解ggplot2绘图核心逻辑 3. 基础绘图示范:柱状图、折线图、散点图 (1)简单柱状图 (2)折线图示范 (3)高级散点图 + 拟合线 4. 精细美化:细节打磨决定专业感 5. 推荐的美化小插件(可选进阶) 6. 小练习:快速上手一幅美化…

Vue3 上传后的文件智能预览(实战体会)

目录 前言1. Demo12. Demo2 前言 &#x1f91f; 找工作&#xff0c;来万码优才&#xff1a;&#x1f449; #小程序://万码优才/r6rqmzDaXpYkJZF 爬虫神器&#xff0c;无代码爬取&#xff0c;就来&#xff1a;bright.cn 此处的基本知识涉及较少&#xff0c;主要以Demo的形式供大…

transformer-实现单层Decoder 层

Decoder Layer 论文地址 https://arxiv.org/pdf/1706.03762 解码器层结构 Transformer解码器层由三种核心组件构成&#xff1a; Masked多头自注意力&#xff1a;关注解码器序列当前位置之前的上下文&#xff08;因果掩码&#xff09; Encoder-Decoder多头注意力&#xff1a;关…

设计模式每日硬核训练 Day 16:责任链模式(Chain of Responsibility Pattern)完整讲解与实战应用

&#x1f504; 回顾 Day 15&#xff1a;享元模式小结 在 Day 15 中&#xff0c;我们学习了享元模式&#xff08;Flyweight Pattern&#xff09;&#xff1a; 通过共享对象&#xff0c;分离内部状态与外部状态&#xff0c;大量减少内存开销。适用于字符渲染、游戏场景、图标缓…

大数据开发环境的安装,配置(Hadoop)

1. 三台linux服务器的安装 1. 安装VMware VMware虚拟机软件是一个“虚拟PC”软件&#xff0c;它使你可以在一台机器上同时运行二个或更多Windows、DOS、LINUX系统。与“多启动”系统相比&#xff0c;VMWare采用了完全不同的概念。 我们可以通过VMware来安装我们的linux虚拟机…

多模态大语言模型arxiv论文略读(四十九)

When Do We Not Need Larger Vision Models? ➡️ 论文标题&#xff1a;When Do We Not Need Larger Vision Models? ➡️ 论文作者&#xff1a;Baifeng Shi, Ziyang Wu, Maolin Mao, Xin Wang, Trevor Darrell ➡️ 研究机构: UC Berkeley、Microsoft Research ➡️ 问题背…

【深度学习与大模型基础】第14章-分类任务与经典分类算法

Part 1&#xff1a;什么是分类任务&#xff1f; 1.1 分类就是“贴标签” 想象你有一堆水果&#xff0c;有苹果&#x1f34e;、橘子&#x1f34a;、香蕉&#x1f34c;&#xff0c;你的任务是让机器学会自动判断一个新水果属于哪一类——这就是分类&#xff08;Classification&…

LeetCode 2906 统计最大元素出现至少K次的子数组(滑动窗口)

给出一个示例&#xff1a; 输入&#xff1a;nums [1,3,2,3,3], k 2 输出&#xff1a;6 解释&#xff1a;包含元素 3 至少 2 次的子数组为&#xff1a;[1,3,2,3]、[1,3,2,3,3]、[3,2,3]、[3,2,3,3]、[2,3,3] 和 [3,3] 。该题也是一个比较简单的滑动窗口的题目&#xff0c;但是…

使用 Spring Boot 进行开发

✨ 使用 Spring Boot 进行开发 ✨ &#x1f4cc; 本节将深入介绍如何高效使用 Spring Boot&#xff0c;涵盖以下核心主题&#xff1a; 1️⃣ &#x1f527; 构建系统 深入了解 Spring Boot 的项目结构和依赖管理 2️⃣ ⚙️ 自动配置 探索 Spring Boot 的自动化配置机制和原…

Qt的WindowFlags窗口怎么选?

Qt.Dialog: 指示窗口是一个对话框&#xff0c;这通常会改变窗口的默认按钮布局&#xff0c;并可能影响窗口框架的样式。Qt.Popup: 指示窗口是一个弹出式窗口&#xff08;例如菜单或提示&#xff09;&#xff0c;它通常是临时的且没有任务栏按钮。Qt.Tool: 标识窗口作为一个工具…