AtCoder Beginner Contest 371
A - Jiro :
题目:
代码:
#include <bits/stdc++.h>using namespace std;typedef long long LL ;
typedef pair<int,int> PII;void solve()
{string a,b, c;cin>>a>>b>>c;string s(3,'a');s[0]=a[0];s[1]=b[0];s[2]=c[0];// a b c// c b a// b a c// c a b // a c b // b c aif(s[0]=='>' && s[1]=='>' && s[2]=='>') cout<<'B';else if(s[0]=='<' && s[1]=='<' && s[2]=='<') cout<<'B';else if(s[0]=='<' && s[1]=='>' && s[2]=='>') cout<<'A';else if(s[0]=='>' && s[1]=='<' && s[2]=='<') cout<<'A';else cout<<'C';}int main()
{int T;// cin>>T;T=1;while(T--){solve();}return 0;
}
B - Taro
题目:
代码:
#include <bits/stdc++.h>using namespace std;typedef long long LL ;
typedef pair<int,int> PII;void solve()
{int n,m;cin>>n>>m;vector<int> a(m);string b(m,' ');vector<int> h(n);for(int i=0; i<m; i++){cin>>a[i]>>b[i];a[i]--;if(b[i]=='M'){h[a[i]]++;}if(h[a[i]]==1 &&b[i]=='M') cout<<"Yes\n";else cout<<"No\n";}}int main()
{int T;// cin>>T;T=1;while(T--){solve();}return 0;
}
C - Make Isomorphic:
题目:
思路:
找到g i 与 h j 顶点的对应关系,枚举(1,..,n) 的全排列,计算每种排列对应的花费,取最小值.
代码:
#include <bits/stdc++.h>
using namespace std;typedef long long LL;
typedef pair<int,int> PII;void solve()
{int n;cin>>n;vector w(n,vector(n,0)),g(n,vector(n,0)), h(n,vector(n,0));int mg;cin>>mg;for(int i=0;i <mg; i++){int a, b;cin>>a>>b;a--, b--;g[a][b]=1;g[b][a]=1;}int mh;cin>>mh;for(int i=0; i<mh; i++){int a,b;cin>>a>>b;a--, b--;h[a][b]=1;h[b][a]=1;}for(int i=0; i<n; i++){for(int j=i+1; j<n; j++){cin>>w[i][j];}}vector<int> p(n);iota(p.begin(),p.end(),0);int ans=1e9;do{int res=0;for(int i=0;i<n; i++){for(int j=i+1; j<n; j++){if(h[i][j]!=g[p[i]][p[j]]){res+=w[i][j];}}}ans=min(ans,res);}while(next_permutation(p.begin(),p.end()));cout<<ans<<"\n";}int main()
{int T;
// cin>>T;T=1;while(T--){solve();}return 0;
}
D - 1D Country:
题目:
思路:
离散化+二分查找
代码:
#include <bits/stdc++.h>using namespace std;typedef long long LL;int main()
{int n;cin>>n;vector<int> x(n+1), p(n+1);x[0]=-0x3f3f3f3f;for(int i=1; i<=n; i++) cin>>x[i];for(int i=1; i<=n; i++) cin>>p[i];vector<LL> s(n+1);for(int i=1; i<=n; i++){s[i]=s[i-1]+p[i];}int q;cin>>q;while(q--){int a,b;cin>>a>>b;int l=lower_bound(x.begin(), x.end(), a)-x.begin();int r=upper_bound(x.begin(), x.end(), b)-x.begin()-1;cout<<s[r]-s[l-1]<<'\n';}return 0;
}
E - I Hate Sigma Problems
题目:
思路:
求每个Ai的贡献,
代码:
#include <bits/stdc++.h>using namespace std;typedef long long LL;int main()
{int n;cin>>n;vector<int> a(n+1);vector<vector<int>> pos(n+1);for(int i=1; i<=n; i++){cin>>a[i];pos[a[i]].push_back(i);} LL ans=0;for(int i=1; i<=n; i++){int ls=0;for(auto j: pos[i]) ans+=1LL*(j-ls)*(n-j+1), ls=j;}cout<<ans<<'\n';
}