当前位置:网站首页>Educational Codeforces Round 132 (Rated for Div. 2)【A~C】
Educational Codeforces Round 132 (Rated for Div. 2)【A~C】
2022-07-29 00:53:00 【Stellaris_ L】
A - Three Doors
The question
There are three doors , Each door has a matching key . The key to a door will be given initially , And put the other two keys behind the two doors , Please open all three doors
Answer key
Jump every time according to the currently available door , When you meet 0 0 0 Quit when you're on the road , Judge whether three doors have been opened at present .
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
ll _;
/*-------------------------------------------------*/
/*-------------------------------------------------*/
ll n,m;
void solve(){
cin>>n;
int a[5],cnt=1;
for(int i=1;i<=3;i++){
cin>>a[i];
}
while(a[n]){
n=a[n];
cnt++;
}
if(cnt==3)puts("YES");
else puts("NO");
}
int main(){
cin>>_;while(_--)
solve();
return 0;
}
B - Also Try Minecraft
The question
Give a length of n n n Array of , a i a_i ai Express i i i The floor height of the location . You can move one unit left or right at a time , If you move from high to low, you will get fall damage with a value of height difference , Seek from s s s Move to t t t Get fall damage .
Answer key
Because the starting point can be larger than the ending point , It can also be smaller than the end , So find the sum of two prefixes , One is from left to right a [ i ] − a [ i − 1 ] a[i]-a[i-1] a[i]−a[i−1] The prefix of and the other is from left to right a [ i − 1 ] − a [ i ] a[i-1]-a[i] a[i−1]−a[i] And , Because in this way, the starting point is greater than the end point to exchange , In this way, we can find two cases according to the same logic .
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
ll _;
/*-------------------------------------------------*/
/*-------------------------------------------------*/
ll n,m;
ll a[N];
ll s1[N];//l->r
ll s2[N];//r->l
void solve(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<n;i++){
ll t1=max(0ll,a[i]-a[i+1]);
ll t2=max(0ll,a[i+1]-a[i]);
s1[i]=s1[i-1]+t1;
s2[i]=s2[i-1]+t2;
}
while(m--){
int s,t;
cin>>s>>t;
if(s<=t){
cout<<s1[t-1]-s1[s-1]<<endl;
}else{
swap(s,t);
cout<<s2[t-1]-s2[s-1]<<endl;
}
}
}
int main(){
//cin>>_;while(_--)
solve();
return 0;
}
C - Recover an RBS
The question
Given a by " ? ? ? “,” ( ( ( “,” ) ) ) " Composed string . among ? ? ? It can be converted to left bracket or right bracket , Determine whether the current string is a unique match .
- Unique match : If it happens ? ? ? It can be either a left bracket or a right bracket , This is not the only match .
Answer key
This question is mainly to determine how to be unique . Here I give three examples :
- ( ? ? ) (??) (??)
- ( ? ? ( ) ) ? ) (??())?) (??())?)
- ( ) ? ? ()?? ()??
There are several rules when matching :
(1) ) ) ) Priority matching ( ( ( If it doesn't exist ( ( ( Just match ? ? ?.
(2) ( ( ( All match perfectly and only one is left ? ? ? Will this ? ? ? Convert to ( ( (.
(3) You can find , If the left and right sides match ? ? ? The rest of , This is not the only .
【 Just went to have a look again , It is found that there must be at least one match in the title, so there will be no “((???((” Data like this ( I thought I was going to be hack 了 )】
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
ll _;
/*-------------------------------------------------*/
/*-------------------------------------------------*/
ll n,m;
void solve(){
string str;
cin>>str;
int cntl=0,cnt=0;
for(int i=0;i<str.size();i++){
if(str[i]=='('){
cntl++;
}else if(str[i]==')'){
if(!cntl){
cnt--;
}else{
cntl--;
}
}else{
cnt++;
}
if(cnt==1&&!cntl){
cnt--;
cntl++;
}
}
cnt-=cntl;
if(!cnt)puts("YES");
else puts("NO");
}
int main(){
cin>>_;while(_--)
solve();
return 0;
}
边栏推荐
- UE4 调试常用的打印信息方法
- 主线程与守护线程
- 第二轮1000个Okaleido Tiger,再次登录Binance NFT 1小时售罄
- [network security] complete the blacklist and whitelist functions of server firewall through iptables and ipset
- NFTScan 与 NFTPlay 在 NFT 数据领域达成战略合作
- CUDA related
- Soft test --- database (4) SQL statement
- Requestvideoframecallback() simple instance
- Statistical analysis of time series
- Asynchronous mode worker thread
猜你喜欢

【esn】 学习回声状态网络

DRF - paging, JWT introduction and principle, JWT quick use, JWT source code analysis, JWT custom return format, custom user issued token, custom token authentication class

将Word中的表格以图片形式复制到微信发送

Summary of preprocessing methods for time series data

15.模型评估和选择问题

17. Design of machine learning system

Anomaly detection and unsupervised learning (2)

Error reporting: when the browser clicks the modify add button, there is no response and no error reporting. Solution

Five interesting magic commands in jupyter notebook

Oracle实例无法启动的问题如何解决
随机推荐
PTA (daily question) 7-77 encryption
Outlier detection and Gan network (1)
15.模型评估和选择问题
【开发教程10】疯壳·开源蓝牙心率防水运动手环-蓝牙 BLE 收发
flask结合容联云发送验证码
Jupyter notebook中5个有趣的魔法命令
AQS原理
软考 --- 数据库(4)SQL语句
There is a span tag. If you want to do click events on it, how can you expand the click area
Statistical analysis of time series
Outlier detection and open set identification (2)
PTA (daily question) 7-73 turning triangle
Breadth first search (BFS) and its matlab code
[network security] complete the blacklist and whitelist functions of server firewall through iptables and ipset
从零开始实现lmax-Disruptor队列(六)Disruptor 解决伪共享、消费者优雅停止实现原理解析
16.偏差、方差、正则化、学习曲线对模型的影响
rk3399 9.0驱动添加Powser按键
SQL Server 只有数据库文件,没有日志文件,恢复数据时报1813错误的解决方案
Outlier detection and open set identification (1)
The download file of native JS implementation can be used anywhere