当前位置:网站首页>Educational Codeforces Round 132 A - D
Educational Codeforces Round 132 A - D
2022-07-22 20:35:00 【追烽】
Educational Codeforces Round 132 (Rated for Div. 2)
提交情况

参考
Educational Codeforces Round 132 (Rated for Div. 2) A - E
A. Three Doors
标签
模拟
代码
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
#define mem(a) memset((a),0,sizeof(a))
// #define int long long
using namespace std;
const int N = 1e5+7;
bool solve(){
int a[10]={
0},b[10]={
0};
FOR(i,0,3) {
cin>>a[i];b[a[i]]++;}
FOR(i,0,3){
if(b[i]!=1)return false;
}
if(a[a[0]]!=0 and a[a[a[0]]]!=0)return true;
else return false;
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
int T=1; cin>>T;
while(T--){
if(solve()) puts("YES");
else puts("NO");
}
return 0;
}
B. Also Try Minecraft
标签
前缀和
代码
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
#define mem(a) memset((a),0,sizeof(a))
#define int long long
#define endl '\n'
using namespace std;
const int N = 1e5+7;
int a[N],b1[N],b2[N],pre1[N],pre2[N];
void solve(){
int n,m; cin>>n>>m;
FOR(i,1,n) cin>>a[i];
FOR(i,1,n){
if(a[i-1]>a[i]) b1[i]=a[i-1]-a[i];
else b2[i]=a[i]-a[i-1];
}
FOR(i,1,n){
pre1[i]=pre1[i-1]+b1[i];
pre2[i]=pre2[i-1]+b2[i];
}
FOR(i,1,m){
int l,r; cin>>l>>r;
if(l<r) cout<<pre1[r]-pre1[l]<<endl;
else cout<<pre2[l]-pre2[r]<<endl;
}
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
int T=1; //cin>>T;
while(T--) solve();
return 0;
}
C. Recover an RBS
标签
贪心, 构造
题意

思路

代码
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
#define mem(a) memset((a),0,sizeof(a))
#define endl '\n'
// #define int long long
using namespace std;
const int N = 2e5+7;
string s;
bool check(int _l,int _r){
FOR(i,0,s.size()-1){
if(s[i]=='?'){
if(_l>=2){
s[i]='(';
_l--;
}
else if(_l==1){
s[i]=')';
_l=-1;
}
else if(_l==-1){
s[i]='(';
_l=-2;
_r--;
}
else if(_r>=1){
s[i]=')';
_r--;
}
}
}
stack<char> stk;
FOR(i,0,s.size()-1){
if(s[i]=='(') stk.push(s[i]);
if(s[i]==')'){
if(!stk.empty()) stk.pop();
else return false;
}
}
return true;
}
void solve(){
cin>>s;
int l=0,r=0,len=s.size();
for(auto i:s){
if(i=='(') l++;
if(i==')') r++;
}
int _l=len/2-l,_r=len/2-r;
if(_l==0 or _r==0) {
puts("YES");return;}
if(check(_l,_r)) puts("NO");
else puts("YES");
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
int T=1; cin>>T;
while(T--) solve();
return 0;
}
D. Rorororobot
标签
贪心, 树状数组, 线段树
题意

思路

代码
(比 C 题容易想多了)
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
#define mem(a) memset((a),0,sizeof(a))
#define endl '\n'
// #define int long long
using namespace std;
const int N = 2e5+7;
int a[N];
struct BIT{
#define MAXN (int)2e5+7
#define INF (int)1e9+7
//const static int MAXN = 2e7+7;
//const static int INF = 1e9+7;
#define maxs(a,b) ((a)>(b)?(a):(b))
#define mins(a,b) ((a)<(b)?(a):(b))
struct node{
int val,i;//数值,原始下标
bool operator<(const node &x)const{
return val<x.val; } bool operator>(const node &x)const{
return val>x.val;
}
};
int n;
node v[MAXN],mi[MAXN],ma[MAXN];
int lowbit(int x){
return x&(-x);
}
void update(int x){
v[x].i=x;
while(x<=n){
mi[x]=ma[x]=v[x];
int lowx=lowbit(x);
for(int i=1;i<lowx;i<<=1){
mi[x]=mins(mi[x],mi[x-i]);
ma[x]=maxs(ma[x],ma[x-i]);
}
x+=lowbit(x);
}
}
node qmin(int l,int r){
//查最小值
node ans=(node){
INF,0};
while(r>=l){
ans=min(ans,v[r]);
for(r=r-1;r-lowbit(r)>=l;r-=lowbit(r))
ans=min(ans,mi[r]);
}
return ans;
}
node qmax(int l,int r){
//查最大值
node ans=(node){
-INF,0};
while(r>=l){
ans=max(ans,v[r]);
for(r=r-1;r-lowbit(r)>=l;r-=lowbit(r))
ans=max(ans,ma[r]);
}
return ans;
}
}tr;
void solve(){
int n,m;
cin>>n>>m;
tr.n=m;
FOR(i,1,m){
cin>>tr.v[i].val;
tr.update(i);
}
int q; cin>>q;
while(q--){
int sx,sy,fx,fy,k;
cin>>sx>>sy>>fx>>fy>>k;
if(sy>fy) {
swap(sx,fx); swap(sy,fy);}
if((sx-fx)%k!=0 or (sy-fy)%k!=0){
cout<<"NO\n";continue;
}
int tp=((n-sx)/k)*k+sx;
if(tp>tr.qmax(sy,fy).val) cout<<"YES\n";
else cout<<"NO\n";
}
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
int T=1; // cin>>T;
while(T--) solve();
return 0;
}
边栏推荐
- 小程序毕设作品之微信酒店预订小程序毕业设计(8)毕业设计论文模板
- Ambire Gas Tank 推出独家 NFT 投放
- AE common expression summary "suggestions collection"
- VR panoramic zoo, a zoo business card with different achievements
- 二叉树的遍历
- Datagrip tutorial (GIF version)
- 浅析缓存的读写策略
- 小程序毕设作品之微信校园二手书交易小程序毕业设计成品(2)小程序功能
- VIM text editor
- 直播预告 | openGauss的自治运维平台DBMind实践分享
猜你喜欢
随机推荐
redis基本类型常用命令
Vector3.Lerp
Esphone's self-made infrared remote control is connected to ha to control lights, switches, etc. any remote control can be used
直播预告 | openGauss的自治运维平台DBMind实践分享
Are most programmers eliminated after the age of 45? The truth chilled everyone's heart
Cloudwego's design practice in the background platform of flybook management
【JDBC】报错Exception in thread “main”com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communica
[C# 数组]-C# 之中的一维数组和对象数组
能量原理与变分法笔记11:形函数(一种降维思想)
园区招商难在“哪”?产业园区招商引资困点难点问题盘点
J9数字论:什么是 Web3.0?Web3.0 有哪些特征?
IP第二次实验 MGRE OSPF
Kotlin learning quick start (8) - Delegation
VR panoramic zoo, a zoo business card with different achievements
0day attack path prediction method based on network defense knowledge map
gnu 伪指令定义函数
标签平滑(label smoothing)
LAN SDN technology hard core insider - what's in the prequel CPU?
[FAQ] common reasons and solutions for the failure of in app payment services to pull up the payment page
最新版Ontrack EasyRecovery电脑数据恢复软件应用









