A
# include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
int a1,b1,a2,b2;
cin>>a1>>b1>>a2>>b2;
if(a1*b1<b2*a2)
cout<<"lz";
else cout<<"gzy";
}
B
# include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
string a,b;
cin>>a>>b;
if(a.find('.')==a.npos)
a+=".00000000000";
else
{
a+="00000000000";
}
if(b.find('.')==b.npos)
b+=".00000000000";
else
{
b+="00000000000";
}
if(a.substr(0,a.find('.')+7)==b.substr(0,b.find('.')+7))
cout<<"YES";
else cout<<"NO";
}
D
可以考虑并查集做 在合并后我们要将一个连通块中点染成一个颜色,每个联通块的大小减去该联通块中出现最多的颜色依次累加即为答案
# include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+10;
int a[N],p[N],sz[N];
int n,m;
unordered_map<int, int> h[N];
int find(int x) // 并查集
{
if (p[x] != x) p[x] = find(p[x]);
return p[x];
}
signed main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i],p[i]=i,sz[i]=1;
while(m--)
{
int a,b;
cin>>a>>b;
int x=find(a),y=find(b);
if(x!=y)
{
p[x]=y;
sz[y]+=sz[x];
}
}
int ans=0;
for(int i=1;i<=n;i++)
h[find(i)][a[i]]++;
for (int i = 1; i <= n; i++) {
if (p[i] == i) {
int ma = 0;
for (auto it : h[i]) {
ma = max(ma, it.second);
}
ans += sz[i] - ma;
}
}
cout<<ans;
}
E
用栈维护即可,全部的括号数也就是n−目前在栈中的左括号数
#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
int n;
cin >> n;
string s;
cin >> s;
s=' '+ s;
stack<int> st;
vector<int> ans(n + 1);
int cnt = 0, flag = 0;
for (int i = 1; i <= n * 2; i ++)
{
if (s[i] == '(')
{
st.push(++cnt);
}
else
{
if (!st.empty())
{
ans[st.top()] = st.size();
st.pop();
}
else
{
flag = 1;
break;
}
}
}
if (flag)
{
cout << -1;
return;
}
for (int i = 1; i <= n; i++)
{
cout << n - ans[i] << ' ';
}
}
signed main() {
ios::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
int t = 1;
//cin >> t;
while (t--)
{
solve();
}
}