Acwing第 54 场周赛

总结

本场比赛难度适中,第一题是一道模拟,第二题是一个简单的枚举,第三题是一道分类讨论。但是但是!!边界很关键,哦不被边界卡了2次。

4428. 字符串

// shiran
#include 
using namespace std;

#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define sz(x) (int)size(x)
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mk make_mair
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 1e9+7;
const int N = 200010, M = 300010;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    set<char> s;

    int n;
    cin >> n;
    string str;
    cin >> str;
    
    for (auto& c : str)
        s.insert(toupper(c));
    if (s.size() == 26)
        puts("YES");
    else
        puts("NO");
    return 0;
}

4429. 无线网络

// shiran
#include 
using namespace std;

#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define sz(x) (int)size(x)
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mk make_mair
typedef long long ll;
typedef pair<ll, ll> PII;
const int mod = 1e9+7;
const int N = 2010, M = 300010;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

ll n, a, b, c, d;
PII p[N];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> n >> a >> b >> c >> d;
    rep(i, 1, n + 1)
    {
        ll x, y;
        cin >> x >> y;
        p[i].fi = (a - x) * (a - x) + (b - y) * (b - y);
        p[i].se = (c - x) * (c - x) + (d - y) * (d - y);
    }
    
    sort(p + 1, p + n + 1);
    
    ll ans = 2e18;
    rep(i, 0, n + 1)
    {
        ll d2 = 0;
        rep(j, i + 1, n + 1)
        {
            d2 = max(d2, p[j].se);
        }
        ans = min(ans, p[i].fi + d2);
    }
    cout << ans << endl;
    return 0;
}

4430. 括号序列

// shiran
#include 
using namespace std;

#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define sz(x) (int)size(x)
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mk make_mair
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 1e9+7;
const int N = 1000010, M = 300010;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

int n;
char s[N];
int fl[N], fr[N];
int lp, rp;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> n >> s + 1;
    int cnt = 0;
    rep(i, 1, n + 1)
    {
        if (s[i] == '(')
            cnt ++ ;
        else
            cnt -- ;
        fl[i] = cnt;
        if (!lp && fl[i] < 0)
            lp = i;
    }
    cnt = 0;
    per(i, n + 1, 1)
    {
        if (s[i] == ')')
            cnt ++ ;
        else 
            cnt -- ;
        fr[i] = cnt;
        if (!rp && cnt < 0)
            rp = i;
    }
    
    if (!lp) lp = n + 1;

    if (lp <= rp) printf("%d\n", 0);
    else
    {
        int j = 1, ans = 0;
        while (j < rp) j ++ ;
        
        if (j == 1 && s[j] == ')')
        {
            if (fr[j + 1] == 1) ans ++ ;
            j ++ ;
        }
        rep(i, j, n)
        {
            if (s[i] == '(' && fl[i] - 2 == fr[i + 1])
                ans ++ ;
            else if (s[i] == ')' && fl[i] + 2 == fr[i + 1])
                ans ++ ;
            if (i > lp) break;
            //cout << ans << endl;
        }
        if (n <= lp)
        {
            if (s[n] == '(' && fl[n - 1] == 1)
                ans ++ ;
        }
        printf("%d\n", ans);
    }
    
    return 0;
}

你可能感兴趣的:(周赛,c++,算法,数据结构,acwing,周赛)