2022.4.15
作者:互联网
AtCoder Beginner Contest 236
A - chukodai
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=1e5+10,INF=1e9;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
int a, b;
cin >> a >> b;
swap(s[a - 1], s[b - 1]);
cout << s;
return 0;
}
B - Who is missing?
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=1e5+10,INF=1e9;
int vis[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= 4 * n - 1;i++)
{
int x;
cin >> x;
vis[x]++;
}
for (int i = 1; i <= n;i++)
{
if(vis[i]==3)
{
cout << i << '\n';
break;
}
}
return 0;
}
C - Route Map
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<string,int> psi;
const int N=1e5+10,INF=1e9;
psi a[N];
map<string, int> mp;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n,m;
cin >> n >> m;
for (int i = 1; i <= n;i++)
{
cin >> a[i].first;
a[i].second = 0;
}
for (int i = 1;i<=m;i++)
{
string s;
cin >> s;
mp[s] = 1;
}
for (int i = 1; i <= n;i++)
{
if(mp[a[i].first])
{
cout << "Yes\n";
}
else
cout << "No\n";
}
return 0;
}
D - Dance
两两配对选择舞伴,以为dfs会超时实际上是不会的,需要注意当一对舞伴被选了后,后面的就不能再重复选其中的任意一个了。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=15+10,INF=1e9;
int a[N][N],ans,n;
bool vis[N];
void dfs(int now,int res)
{
if(now==0)
{
ans = max(res, ans);
return;
}
if(vis[now])
{
dfs(now - 1, res);
return;
}
for (int i = 1; i <= n ;i++)
{
if(!vis[i]&&i!=now)//当前的层数和选的数都没有没选过
{
vis[i] = 1;
vis[now] = 1;
dfs(now - 1, res ^ a[now][i]);
vis[i] = 0;//还原现场
vis[now] = 0;
}
}
return;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
n = n * 2;
for (int i = 1; i < n;i++)
{
for (int j = i+1; j <= n;j++)
{
cin >> a[i][j];
a[j][i] = a[i][j];
}
}
dfs(n-1, 0);
cout << ans;
return 0;
}
标签:typedef,15,int,cin,long,vis,2022.4,include 来源: https://www.cnblogs.com/menitrust/p/16151379.html