Educational Codeforces Round 105 (Rated for Div. 2) AB题解
A. ABC String
思路:相同字符要有相同的半括号(要么都是左括号要么都是右括号),总共8种情况。若把左括号看做1,右括号看成-1,那么这个序列满足任意前缀和\(sum[i]>=0且sum[n]==0\),对每种情况进行检验即可。
view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
int main()
{
int kase;
cin>>kase;
while(kase--)
{
string s;
cin>>s;
bool ok = false;
for(int A=1, cnt1 = 1; cnt1<=2; cnt1++, A *= -1)
for(int B=1, cnt2 = 1; cnt2<=2; cnt2++, B *= -1)
for(int C=1, cnt3 = 1; cnt3<=2; cnt3++, C *= -1)
{
int sum[55];
mem(sum,0);
map<char, int> Map;
if(A==1) Map['A'] = 1;
else Map['A'] = -1;
if(B==1) Map['B'] = 1;
else Map['B'] = -1;
if(C==1) Map['C'] = 1;
else Map['C'] = -1;
string t = s;
for(int i=0; i<t.size(); i++) sum[i+1] = sum[i] + Map[t[i]];
int flag = 1;
for(int i=1; i<=t.size(); i++)
{
if(sum[i]<0||sum[t.size()] != 0)
{
flag = 0;
break;
}
}
if(flag)
{
ok = true;
break;
}
}
puts(ok?"YES":"NO");
}
return 0;
}
B. Berland Crossword
思路:其实各边能产生关系的也就四个顶点。所以枚举一下四个顶点有无填黑的情况(我这里采用四位二进制表示),看看剩下的n-2个位置能否满足对应数量的黑块即可。
view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
ll a[10];
int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll n = read();
rep(i,1,4) a[i] = read();
int flag = 0;
for(ll i=0; i<16; i++)
{
int TopLeft = (i&1);
int TopRight = (i>>1)&1;
int BottomLeft = (i>>2)&1;
int BottomRight = (i>>3)&1;
int U = a[1];
int R = a[2];
int D = a[3];
int L = a[4];
U -= TopLeft;
U -= TopRight;
R -= TopRight;
R -= BottomRight;
D -= BottomRight;
D -= BottomLeft;
L -= BottomLeft;
L -= TopLeft;
if(U>=0&&R>=0&&D>=0&&L>=0&&U<=n-2&&R<=n-2&&D<=n-2&&L<=n-2)
{
flag = 1;
break;
}
}
puts(flag?"YES":"NO");
}
return 0;
}
Educational Codeforces Round 105 (Rated for Div. 2) AB题解的更多相关文章
- Educational Codeforces Round 48 (Rated for Div. 2) CD题解
Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...
- Educational Codeforces Round 59 (Rated for Div. 2) DE题解
Educational Codeforces Round 59 (Rated for Div. 2) D. Compression 题目链接:https://codeforces.com/contes ...
- Educational Codeforces Round 105 (Rated for Div. 2)
A. ABC String 题目:就是用'('和')'来代替A,B,C并与之对应,问是不是存在这样的对应关系使得'('和')'正好匹配 思路:第一个和最后一个字母是确定的左括号或者是右括号,这样就还剩 ...
- Educational Codeforces Round 57 (Rated for Div. 2) ABCDEF题解
题目总链接:https://codeforces.com/contest/1096 A. Find Divisible 题意: 给出l,r,在[l,r]里面找两个数x,y,使得y%x==0,保证有解. ...
- Educational Codeforces Round 80 (Rated for Div. 2)部分题解
A. Deadline 题目链接 题目大意 给你\(n,d\)两个数,问是否存在\(x\)使得\(x+\frac{d}{x+1}\leq n\),其中\(\frac{d}{x+1}\)向上取整. 解题 ...
- Educational Codeforces Round 64 (Rated for Div. 2)题解
Educational Codeforces Round 64 (Rated for Div. 2)题解 题目链接 A. Inscribed Figures 水题,但是坑了很多人.需要注意以下就是正方 ...
- [Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和)
[Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和) E. Permuta ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
随机推荐
- 解释Spring框架中bean的生命周期
一.Bean生命周期的流程图 二.spring的生命周期 spring生命周期中的阶段,包括初始化.使用.销毁. 1.初始化阶段 1)调用bean的构造函数,创建实例: 2)进行参数依赖注入: 3)若 ...
- 微信接龙转Excel
1.新建Excel表格 2.将微信接龙信息复制至表格 3.选择列 4.选择[数据]->[分列] 5.选择[分隔符号]->[下一步] 6.选择[分隔符号]->[下一步] 这里以[空格] ...
- C#之集合常用扩展方法与Linq
一.集合的常用扩展方法(lambda的方式) 1.Where() 根据条件选择数据 2.Select() 根据数据条件转换成新的数据类型,类似于DTO转换类 3.Max() 根据条件选择最大值 4.M ...
- 定时任务Cron表达式工具类Cron Util
依赖 cron-utils的github地址:https://github.com/jmrozanec/cron-utils <dependency> <groupId>com ...
- 代码随想录第二十天 | Leecode 235. 二叉搜索树的最近公共祖先 、 701.二叉搜索树中的插入操作 、450.删除二叉搜索树中的节点
Leecode 235. 二叉搜索树的最近公共祖先 题目描述 给定一个二叉搜索树, 找到该树中两个指定节点的最近公共祖先. 百度百科中最近公共祖先的定义为:"对于有根树 T 的两个结点 p. ...
- 【经验】CiteSpace|Wiley Online Library或除知网以外的其他网站的文献怎么导入CiteSpace 6.1.6?
如果没安装,请看这篇博客安装,现在新版(6.1.6)的不需要额外下载java了,就很妙~: 最新版citespace软件的安装与配置 结论:导出成RIS然后用它自带的转换成WoS. 文章目 ...
- 鸿蒙Next开发实战教程--银行App
昨天Mate70的官方预热直接引起网络爆炸,现在预约人数已经两百多万了,大家都这么有米吗 今天跟大家分享一个银行app实战教程. 页面虽然看起来比较复杂,但是仔细分析一下并不难,下面跟大家分享一下本项 ...
- c#开发完整的Socks5代理客户端与服务端(已完结)
本文我们介绍下如何在Windows系统上开发一个代理本机流量的客户端,并且对接我们之前开发的Socks5服务端,实现整个代理的一条龙.对于Socks5代理的服务端的开发可以详见之前的文章. 目录 本机 ...
- c++并发编程实战-第4章 并发操作的同步
等待事件或等待其他条件 坐车案例 想象一种情况:假设晚上坐车外出,如何才能确保不坐过站又能使自己最轻松? 方法一:不睡觉,时刻关注自己的位置 1 #include <iostream> 2 ...
- SgLang代码细读-1.从req到batch
SgLang代码细读-1.从req到batch 代码入口 & 初始化 sglang/python/sglang/srt/entrypoints/http_server.py launch_se ...