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 ...
随机推荐
- Linux实战笔记__Centos7上搭建DVWA网站(基于宝塔)
安装宝塔套件 宝塔官网有远程安装代码https://www.bt.cn/bbs/thread-19376-1-1.html 下载DVWA并上传至/www/wwwroot目录 下载地址: 配置数据库连接 ...
- 【单片机入门】(三)应用层软件开发的单片机学习之路-----UART串口通讯和c#交互
引言 在第一章博客中,我们讲了Arduino对Esp32的一个环境配置,以及了解到了常用的一个总线通讯协议,其中有SPI,IIC,UART等,今天我为大家带来UART串口通讯和c#串口进行通讯的一个案 ...
- Istio(十一):向istio服务网格中引入虚拟机
目录 一.模块概览 二.系统环境 三.虚拟机负载 3.1 虚拟机负载 3.2 单网络架构 3.3 多网络架构 3.4 Istio 中如何表示虚拟机工作负载? 四.实战:向istio Mesh中引入虚拟 ...
- 苹果 App Store 开始支持隐藏上架应用:只能通过链接下载
据MacRumors报道,苹果公司最近宣布,正如其开发者网站上所概述的那样,App Store现在支持只能通过直接链接才能发现的隐藏应用. 图片来自 Apple 拥有不适合公开发布的应用的开发 ...
- 使用jmx exporter采集kafka指标
预置条件 安装kafka.prometheus 使用JMX exporter暴露指标 下载jmx exporter以及配置文件.Jmx exporter中包含了kafka各个组件的指标,如server ...
- Python基础部分:8、for循环和range的使用
目录 一.while循环补充说明 1.死循环 2.嵌套及全局标志位 二.for...循环 1.for...循环特点 2.for...循环语法结构 三.range方法 1.什么是range 2.不同版本 ...
- HPL Study 2
1.并行编程 (1)并行程序的逻辑: 1)将当前问题划分为多个子任务 2)考虑任务间所需要的通信通道 3)将任务聚合成复合任务 4)将复合任务分配到核上 (2)共享内存编程: 路障 ----> ...
- EXCEL_BASIC
公式类 比较大小 A1单元格的值大于B1单元格时为"A",小于时为"a",等于时为"e" =IF(A1>B1,"A" ...
- 嵌入式-C语言基础:数组指针
定义一个数组指针,指向二维数组: int a[3][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12}}; int (*p)[4];//定义二维指针数组 p=a;//指向二维数组 ...
- 字符编码 XUTF
/* * Copyright (c) Huawei Technologies Co., Ltd. 2019-2020. All rights reserved. * Description: 上机编程 ...