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题解的更多相关文章

  1. Educational Codeforces Round 48 (Rated for Div. 2) CD题解

    Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...

  2. Educational Codeforces Round 59 (Rated for Div. 2) DE题解

    Educational Codeforces Round 59 (Rated for Div. 2) D. Compression 题目链接:https://codeforces.com/contes ...

  3. Educational Codeforces Round 105 (Rated for Div. 2)

    A. ABC String 题目:就是用'('和')'来代替A,B,C并与之对应,问是不是存在这样的对应关系使得'('和')'正好匹配 思路:第一个和最后一个字母是确定的左括号或者是右括号,这样就还剩 ...

  4. 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,保证有解. ...

  5. Educational Codeforces Round 80 (Rated for Div. 2)部分题解

    A. Deadline 题目链接 题目大意 给你\(n,d\)两个数,问是否存在\(x\)使得\(x+\frac{d}{x+1}\leq n\),其中\(\frac{d}{x+1}\)向上取整. 解题 ...

  6. Educational Codeforces Round 64 (Rated for Div. 2)题解

    Educational Codeforces Round 64 (Rated for Div. 2)题解 题目链接 A. Inscribed Figures 水题,但是坑了很多人.需要注意以下就是正方 ...

  7. [Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和)

    [Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和) E. Permuta ...

  8. 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 ...

  9. 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 ...

  10. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

随机推荐

  1. MySQL的limit优化2

    一.底层原理 在 MySQL 8.0 中,当使用 LIMIT offset, count 进行分页查询时,如果 offset 非常大(例如 LIMIT 200000, 10),性能会显著下降. 这是因 ...

  2. bat文件简短

    bat文件 @echo off F: cd\pictures\projectStreet\FloatingShinyKnot-main node server.js cd\ bat静默运行(但会闪一下 ...

  3. ​.NET AI Preview 2 发布:支持 Aspire 与 Qdrant 向量库集成,加速云原生 AI 开发​

    引言 随着人工智能(AI)技术的迅猛发展,开发者对简单.高效的AI开发工具需求日益增加.微软 .NET 团队最近发布了 .NET AI 模板的 Preview 2 版本,这一更新为开发者带来了诸多令人 ...

  4. 编写一个最原始的Servlet

    目录 1 简介 2 编写程序 1 简介 Servlet(Server Applet)是 Java Servlet 的简称,是使用 Java 语言编写的运行在服务器端的程序.具有独立于平台和协议的特性, ...

  5. 如何在 AI 小助手对话中显示原文预览

    写在前面 本文使用的开源工具平台包含以下内容: AI 助手平台:MaxKB 运维管理面板:1Panel Linux运维管理面板 一.整理原文链接 如果现有的文档已经有能够下载的链接或者预览链接,可以跳 ...

  6. 从零开始,打造一款属于自己的JavaScript编程语言

    @charset "UTF-8"; .markdown-body { line-height: 1.75; font-weight: 400; font-size: 15px; o ...

  7. AutoCAD AutoLISP 中使用 entmake 创建标注样式(DIMSTYLE)的深度解析

    前言 在 AutoCAD 二次开发中,entmake 函数相比 command 命令具有三大核心优势: 高效性:直接操作图形数据库,避免交互式命令延迟 稳定性:消除命令行参数解析导致的不可控错误 精确 ...

  8. 阿里云部署Django主要注意事项

    (1)virtualenv 报错 os 没有 PathLike属性 阿里云ubuntu16.0服务器默认python版本分别是2.7.12,3.5.2,而PathLike是在python 3.6时才被 ...

  9. uni-app项目从0-1基础架构搭建全流程

    前情 最近新接了一个全新项目,我负责从0开始搭建小程序,我选用的技术栈是uni-app技术栈,UI库选择的是uview-plus,CSS引入现在流行的tainlwindcss,实现CSS原子化书写,实 ...

  10. 题解:AT_abc402_d [ABC402D] Line Crossing

    题目中说直线相交,由于这是二维平面,我们可以知道直线要么相交,要么平行,所以我们可以求平行. 观察题目中的这个图,我们可以发现一个性质: 当标号相加的和取余点的个数相同时,这两条直线平行. 知道这个我 ...