AcWing 第 54 场周赛

115 篇文章 3 订阅
20 篇文章 0 订阅

4428. 字符串

在这里插入图片描述

#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int n;
    cin>>n;
    cin>>s;
    map<int,int>mp;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]>='a'&&s[i]<='z')mp[s[i]-'a']++;
        if(s[i]>='A'&&s[i]<='Z')mp[s[i]-'A']++;
    }
        if(mp.size()==26)cout<<"YES";
        else cout<<"NO";
}

4429. 无线网络

在这里插入图片描述

#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long 
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define LL_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
PII s1,s2;
int dist(PII a,PII b)
{
	return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
void solve()
{
    int n,x1,y1,x2,y2;
	cin>>n>>x1>>y1>>x2>>y2;
	vector<PII>v(n+1);
	s1.x=x1,s1.y=y1,s2.x=x2,s2.y=y2;
	for(int i=1;i<=n;i++)
	{
		int x,y;
		cin>>x>>y;
		v[i].x=dist({x,y},s1),v[i].y=dist({x,y},s2);
	}
	sort(all(v));
	int res=LL_INF;
	v[0]={0,0};
	for(int i=0;i<=n;i++)
	{
		int d1=v[i].x;
		int maxv=0;
		for(int j=0;j<=n;j++)
		{
			int d2=v[j].y;
			if(v[j].x<=d1)continue;
			maxv=max(maxv,d2);
		}
		res=min(res,maxv+d1);
	}
	cout<<res<<endl;
}
signed main()
{
	io;
//	cin>>_;
	//while(_--)
	solve();
	return 0;
}

4430. 括号序列

在这里插入图片描述

#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long 
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n;
string s;
int judge()
{
	int cnt=0,r=0;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='(')cnt++;
		else
		{
			cnt--;
			r++;
			if(cnt<0)
			{
				cnt+=2;
				for(int j=i+1;j<n;j++)
				{
					if(s[j]=='(')cnt++;
					else
					{
						cnt--;
						if(cnt<0)return 0;
					}
				}
				return r;
			}
		}
	}
}
void solve()
{
	cin>>n;
	cin>>s;
	int l=0,r=0;
	for(auto x:s)
		if(x=='(')l++;
		else r++;
	if(r==2+l)cout<<judge()<<endl;
	else if(l==r+2)
	{
		reverse(all(s));
		for(int i=0;i<n;i++)
			if(s[i]=='(')s[i]=')';
			else s[i]='(';
		cout<<judge()<<endl;
	}
	else cout<<0<<endl;
}
signed main()
{
	io;
//	cin>>_;
	//while(_--)
	solve();
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

leimingzeOuO

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值