太忙了,这次写不了题解啦
A
·模拟
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int main()
{
int T;
cin >> T;
while(T --)
{
cin >> n >> m;
vector<int> a(n);
for(int i = 0; i < n; i ++) cin >> a[i];
sort(a.begin(), a.end());
reverse(a.begin(), a.end());
int ff = a[0], ss = a[1];
int r = (m / (ff + ss)) * 2;
m %= (ff + ss);
if(!m) cout << r << endl;
else if(m > ff) cout << r + 2 << endl;
else cout << r + 1 << endl;
}
return 0;
}
B
·找规律
#include <bits/stdc++.h>
using namespace std;
int n, m;
int main()
{
int T;
cin >> T;
while(T --)
{
cin >> n >> m;
vector<int> a(n), b(n);
for(int i = 0; i < n; i ++) cin >> a[i], b[i] = a[i];
sort(b.begin(), b.end());
bool suc = true;
for(int i = n - m; i <= m - 1; i ++) if(b[i] != a[i]) suc = false;
if(suc) cout << "YES" << endl;
else cout << "NO" << endl;
}
}
C
·数学(?
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int t, n, k, x, y, a[N], cnt;
bool st[N];
vector<int> h[N];
int dfs(int i, int s)
{
int u = a[i];
st[i] = true;
for(auto x : h[i]) if(!st[x]) u ^= dfs(x, s);
if(u == s)
{
cnt ++;
return 0;
}
return u;
}
int main()
{
cin >> t;
while(t --)
{
cin >> n >> k;
int s = 0;
for(int i = 1; i <= n; i ++) cin >> a[i], s ^= a[i], h[i].clear();
for(int i = 1; i < n; i ++)
{
cin >> x >> y;
h[x].push_back(y);
h[y].push_back(x);
}
if(!s)
{
cout << "YES\n";
continue;
}
cnt = 0;
memset(st, 0, sizeof st);
dfs(1, s);
if(cnt >= 3 && k >= 3) cout << "YES\n";
else cout << "NO\n";
}
}
D
·dfs
#include<bits/stdc++.h>
using namespace std;
const int N = 1117;
pair<int, int> sides[N];
vector<int> h[N];
bool st[N];
int n, x, y, t, cnt;
void dfs(int a, int b)
{
sides[++cnt] = {a, b};
for(auto u : h[b]) if(u != a) dfs(b, u);
}
int main()
{
cin >> n;
for(int i = 1; i < n; i ++) cin >> x >> y, h[x].push_back(y), h[y].push_back(x);
for(auto i : h[1]) dfs(1, i);
cout << "? " << n;
for(int i = 1; i <= n; i ++) cout << ' ' << i;
cout << endl;
cin >> t;
int l = 1, r = n - 1, m;
while(l < r)
{
m = l + r >> 1;
set<int> s;
for(int i = l; i <= m; i ++) s.insert(sides[i].first), s.insert(sides[i].second);
cout << "? " << s.size() << ' ';
for(auto i : s) cout << i << ' ';
cout << endl;
int u;
cin >> u;
if(t == u) r = m;
else l = m + 1;
}
cout << "! " << sides[l].first << ' ' << sides[l].second << endl;
}