codeforce div3 A-D
A:签到
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <math.h>
using namespace std;
typedef long long ll;
const int N = 1005;
const int maxn = 1e6 + 5;
ll bas[65], cnt;
int a[4];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
for (int i = 0; i < 3; i++)
cin >> a[i];
sort(a, a + 3);
if (a[2] == a[1])
{
cout << "YES" << endl;
cout << a[0] << ' ' << a[0] << ' ' << a[2] << endl;
}
else
{
cout << "NO" << endl;
}
}
}
B:签到
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <math.h>
using namespace std;
typedef long long ll;
const int N = 1005;
const int maxn = 1e6 + 5;
ll bas[65], cnt;
int a[4];
map<int,int>vis;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
int n;
cin>>n;
vis.clear();
for(int i=0;i<n*2;i++)
{
int x;
cin>>x;
if(!vis[x])
{
cout<<x<<' ';
vis[x]=1;
}
}
cout<<endl;
}
}
C: 模拟
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <math.h>
using namespace std;
typedef long long ll;
const int N = 1005;
const int maxn = 1e6 + 5;
ll bas[65], cnt;
int a[maxn];
map<int, int> vis;
int q[maxn];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
int j = 0, l = 1, r = n, top = 0;
while (l <= r)
{
bool flc = false;
if (a[l] <= a[r])
{
if (a[l] >= q[top])
q[++top] = a[l], l++, flc = true;
}
else
{
if (a[r] >= q[top])
q[++top] = a[r], r--, flc = true;
}
if (!flc)
j = l, r = n, l++, top = 0;
}
if (j == 0)
{
cout << j << endl;
continue;
}
l = j, r = n, top = 0;
bool fla = true;
while (l <= r)
{
bool flc = false;
if (a[l] <= a[r])
{
if (a[l] >= q[top])
q[++top] = a[l], l++, flc = true;
}
else
{
if (a[r] >= q[top])
q[++top] = a[r], r--, flc = true;
}
if (!flc)
{
r = n, l++, top = 0;
fla = false;
break;
}
}
if (fla)
j--;
cout << j << endl;
}
}
D: 分治+dfs
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <math.h>
using namespace std;
const int N = 1005;
typedef long long ll;
const int maxn = 1e6 + 5;
ll bas[65], cnt;
int a[maxn];
int q[maxn];
map<int, int> vis;
vector<int> vec;
int check(string s, char ch)//检查当前字符串全程ch需要变多少个
{
int n = s.size(), ans = 0;
for (int i = 0; i < n; i++)
if (s[i] != ch)
ans++;
return ans;
}
int dfs(string s, char ch, int ans)
{
if (s.size() == 1)
{
if (s[0] != ch)
ans++;
return ans;
}
string s1 = s.substr(0, s.size() / 2);
string s2 = s.substr(s.size() / 2, s.size());
int ans1 = check(s1, ch);
int ans2 = check(s2, ch);
return min(ans2+dfs(s1, ch + 1, ans),ans1+dfs(s2, ch + 1, ans));
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
int n;
cin>>n;
string s;
cin >> s;
cout << dfs(s, 'a', 0) << endl;
}
}