A - Appalling Architecture(搜索+图形重心)
传送门
B - Bee Problem(棋盘搜索)
传送门
E. Eating Everything Efficiently(状压DP)
传送门
H - H to O(字符串模拟)
题目链接
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/6cf9c2b0e39d3813fb16efdc961e5ef2.png#pic_center)
#include <iostream>
#include <string>
#include <cstring>
#include <set>
using namespace std;
#define INF 0x3f3f3f3f
int a[30],b[30];
string s,p;
int n;
int getNum(string str){
int ans=0;
for(int i=0;i<str.size();i++)
ans=ans*10+str[i]-'0';
return ans;
}
int main()
{
cin>>s;
cin>>n;
cin>>p;
memset(a,0,sizeof a);
memset(b,0,sizeof b);
for(int i=0;i<s.size();i++){
if(s[i]>='A' && s[i]<='Z'){
int j=i+1;
string res="";
while(s[j]>='0' && s[j]<='9' && j<s.size()){
res+=s[j++];
}
int num=getNum(res);
if(num) a[s[i]-'A']+=getNum(res)*n;
else a[s[i]-'A']+=n;
i=j-1;
}
}
set<char> se;
for(int i=0;i<p.size();i++){
if(isalpha(p[i])){
se.insert(p[i]);
int j=i+1;
string res="";
while(isdigit(p[j]) && j<p.size()) res+=p[j++];
int num=getNum(res);
if(num) b[p[i]-'A']+=getNum(res);
else b[p[i]-'A']+=1;
i=j-1;
}
}
int ans=INF;
for(auto it : se){
if(b[it-'A']==0){
ans=INF;
break;
}
ans=min(a[it-'A']/b[it-'A'],ans);
}
if(ans!=INF)
cout<<ans<<endl;
else cout<<"0"<<endl;
return 0;
}
J - Jurassic Jigsaw(最小生成树)
题目链接
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/a706ce5789805a060e52731ad26741c4.png#pic_center)
#include<bits/stdc++.h>
#define ll long long
using namespace std;
typedef pair<int,int> P;
const int N=1005;
struct node{
int u,v,w;
node(int a,int b,int c){
u=a,v=b,w=c;
}
bool operator < (node t) const {
return w>t.w;
}
};
char mp[N][15];
int n,m,father[N];
priority_queue<node> p;
queue<P> q;
int Find(int x){
return x==father[x]?x:father[x]=Find(father[x]);
}
void Union(int x,int y){
int fx=father[x],fy=father[y];
if(fx!=fy)
father[fx]=fy;
}
void kruskal(){
int ans=0;
for(int i=0;i<=n;i++) father[i]=i;
while(!p.empty()){
node temp=p.top();
p.pop();
if(Find(temp.u)==Find(temp.v)) continue;
ans+=temp.w;
Union(temp.u,temp.v);
q.push(make_pair(temp.u,temp.v));
}
printf("%d\n",ans);
}
int f(int x,int y){
int ans=0;
for(int i=0;i<m;i++)
if(mp[x][i]!=mp[y][i]) ans++;
return ans;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
scanf("%s",mp[i]);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++)
p.push(node(i,j,f(i,j)));
}
kruskal();
while(!q.empty()){
P u=q.front();
printf("%d %d\n",u.first,u.second); q.pop();
}
return 0;
}