Educational Codeforces Round 33 (Rated for Div. 2) 虚拟赛体验
前言

就只做出了 \(A,B,C,D\) 是不是很弱?
A.Chess For Three
A,B,C 三人下棋,A和B先下,每次下完棋之后由现在观战的人(例如第一局就由C)代替下输的人。 每次输入一个数表示谁赢了(A是1,B是2,C是3),如果每一次输入的赢家都不是当时旁观者,则输出 “YES”,否则输出“NO”。
预计难度普及-。
直接模拟即可。
#include <bits/stdc++.h>
using namespace std;
int n;
int ret=0;
signed main(){
cin>>n;
ret=3;
for(int i=1;i<=n;i++){
int v;
cin>>v;if(v==ret){
cout<<"NO";
return 0;
}
if(ret==1){
ret=5-v;
}
else if(ret==2){
ret=4-v;
}
else{
ret=3-v;
}
}
cout<<"YES";
return 0;
}
B.Beautiful Divisors
给定n,求n最大的因数s,使s能表示成 \((2^k-1)*(2^{k-1})\) 的形式
预计难度普及-。
暴力枚举 \(O(n\log n)\) 可过。
#include <bits/stdc++.h>
using namespace std;
int n;
int ret=1;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
if(!(n%i)){
for(int k=1;(pow(2,k)-1)*(pow(2,k-1))<=i;k++){
if((pow(2,k)-1)*(pow(2,k-1))==i){
ret=i;
break;
}
}
}
}
cout<<ret;
}
C.Rumor
有n个人,其中有m对朋友,现在你有一个秘密你想告诉所有人,第i个人愿意出价a[i]买你的秘密,获得秘密的人会免费告诉它的所有朋友(他朋友的朋友也会免费知道),现在他们想出最少的价钱买秘密,那么你最少能得到多少钱?
预计难度普及。(洛谷难度提高+,有点虚高)
考虑并查集。显然,如果谁的秘密低,就当作并查集的根节点,朋友和朋友之间连边,这样子只要买根节点就可以了。
时间复杂度 \(O(n+m\log n)\)。
代码:
#include <bits/stdc++.h>
#define int long long
using namespace std;
int a[1000005];
namespace UnionFind{
int fa[1000005];
int find(int x){
if(fa[x]==x)return fa[x];
else return fa[x]=find(fa[x]);
}
void merge(int x,int y){
if(a[find(x)]>a[find(y)]){
fa[find(x)]=find(y);
}
else{
fa[find(y)]=fa[find(x)];
}
}
}
int n,m;
int isroot[1000005];
int ret=0;
signed main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
UnionFind::fa[i]=i;
}
for(int i=1,liwenx,daniel2020;i<=m;i++){
cin>>liwenx>>daniel2020;
UnionFind::merge(liwenx,daniel2020);
}
for(int i=1;i<=n;i++){
int rt=UnionFind::find(i);
if(!isroot[rt]){
ret+=a[rt];
isroot[rt]=1;
}
}
cout<<ret;
return 0;
}
D.Credit Card
Recenlty Luba有一张信用卡可用,一开始金额为0,每天早上可以去充任意数量的钱。到了晚上,银行会对信用卡进行一次操作,操作有三种操作。 1.如果a[i]>0,银行会给卡充入a[i]元。 2.如果a[i]<0 银行从卡中扣除a[i]元。 3.如果a[i]=0 银行会查询卡里的金额。 有两条规则,如果违背信用卡就会被冻结。 1.信用卡里的金额不能大于d。 2.当银行查询卡里的金额时,金额不能为负。 Recenlty Luba想知道最少去充多少次钱,可以使她在接下来的n天里信用卡不被冻结。
预计难度提高。
这道题考虑贪心。维护最大和最小,如果最小的都大于 \(t\) 显然无解。如果最大都要充钱那么计数器++,最后输出计数器。
时间复杂度 \(O(n)\)。
代码:
#include <bits/stdc++.h>
#define NO_SOLVE cout<<-1;return 0
using namespace std;
int n,d;
int least,most;
int now;
int ans;
signed main(){
cin>>n>>d;
for(int i=1;i<=n;i++){
cin>>now;
if(now!=0){
least+=now;
most+=now;
if(least>d){
NO_SOLVE;
}
most=min(most,d);
}
else{
least=max(least,0);
if(most<0){
ans++;
most=d;
}
}
}
cout<<ans<<'\n';
return 0;
}
Educational Codeforces Round 33 (Rated for Div. 2) 虚拟赛体验的更多相关文章
- Educational Codeforces Round 33 (Rated for Div. 2) E. Counting Arrays
题目链接 题意:给你两个数x,yx,yx,y,让你构造一些长为yyy的数列,让这个数列的累乘为xxx,输出方案数. 思路:考虑对xxx进行质因数分解,设某个质因子PiP_iPi的的幂为kkk,则这个 ...
- Educational Codeforces Round 33 (Rated for Div. 2) F. Subtree Minimum Query(主席树合并)
题意 给定一棵 \(n\) 个点的带点权树,以 \(1\) 为根, \(m\) 次询问,每次询问给出两个值 \(p, k\) ,求以下值: \(p\) 的子树中距离 \(p \le k\) 的所有点权 ...
- Educational Codeforces Round 33 (Rated for Div. 2) 题解
A.每个状态只有一种后续转移,判断每次转移是否都合法即可. #include <iostream> #include <cstdio> using namespace std; ...
- Educational Codeforces Round 33 (Rated for Div. 2)A-F
总的来说这套题还是很不错的,让我对主席树有了更深的了解 A:水题,模拟即可 #include<bits/stdc++.h> #define fi first #define se seco ...
- Educational Codeforces Round 33 (Rated for Div. 2) D. Credit Card
D. Credit Card time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Educational Codeforces Round 33 (Rated for Div. 2) C. Rumor【并查集+贪心/维护集合最小值】
C. Rumor time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- Educational Codeforces Round 33 (Rated for Div. 2) B. Beautiful Divisors【进制思维/打表】
B. Beautiful Divisors time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Educational Codeforces Round 33 (Rated for Div. 2) A. Chess For Three【模拟/逻辑推理】
A. Chess For Three time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Educational Codeforces Round 33 (Rated for Div. 2)
A. Chess For Three time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Educational Codeforces Round 33 (Rated for Div. 2) D题 【贪心:前缀和+后缀最值好题】
D. Credit Card Recenlty Luba got a credit card and started to use it. Let's consider n consecutive d ...
随机推荐
- Java编程基础——敬请期待!!!
变量 数据类型 条件判断 循环 函数 类 Java特性
- 齐博x1更新了 提供一个部分用户期待已久的功能,修改主题后变为待审
如下图所示,你可以设置哪些用户组修改主题后,就会把原来已审核通过的主题,变为未审核.适合所有频道.
- 【Kubernetes】K8s笔记(十一):Ingress 集群进出流量总管
目录 0. Ingress 解决了什么问题 1. Ingress Controller 2. 指定 Ingress Class 使用多个 Ingress Controller 3. 使用 YAML 描 ...
- Python标准库之 xml.etree.ElementTree
Element类型是一种灵活的容器对象,用于在内存中存储结构化数据. 每个element对象都具有以下属性: 1. tag:string对象,表示数据代表的种类. 2. attrib:dictiona ...
- 阿里云 ACK 接入观测云
简介 容器服务 Kubernetes 版(简称 ACK)提供高性能可伸缩的容器应用管理能力,支持企业级容器化应用的全生命周期管理.2021 年成为国内唯一连续三年入选 Gartner 公共云容器报告的 ...
- HTTPS详解一
前言 作为一个有追求的程序员,了解行业发展趋势和扩充自己的计算机知识储备都是很有必要的,特别是一些计算机基础方面的内容,就比如本篇文章要讲的计算机网络方面的知识.本文将为大家详细梳理一下 HTTPS ...
- 深度学习之深L层神经网络
声明 本文参考(8条消息) [中文][吴恩达课后编程作业]Course 1 - 神经网络和深度学习 - 第四周作业(1&2)_何宽的博客-CSDN博客 力求自己理解,刚刚走进深度学习希望可以一 ...
- RabbitMq了解
RibbitMQ MQ优势 MQ的三大主要作用: 应用解耦.异步提速.流量削锋 应用解耦 系统的耦合性越高,容错性就越低,可维护性就越低: 解耦: 如果其中一个系统服务宕机,那么系统的其他服务将也无法 ...
- 6. PyQt5 中的多线程的使用(上)
专栏地址 ʅ(‾◡◝)ʃ 这一节引入了多线程这个非常重要概念, 在我认为多线程的重要性是紧紧次于信号与槽函数的, 因为在平时经常使用 1. 为什么要用多线程 先看下面这一个示例代码 6.1 from ...
- 关于 python 的内存机制
先看一段代码 L = [1,2,3] dic_ = {} L2 = [] for i in L: dic_['sn'] = i L2.append(dic_) print(L2) 输出 [{'sn': ...