
浙江海洋大学 - 神经舵手 遗憾打铁
赛时通过:A、K、G、L
A

贪心,带点博弈论。以博弈的思考方式看待这个问题,考虑对手是最优情况下,需要多少扭蛋。那么对手一定会给你一个类别的并且是最多到最少,这样的话只需要遍历找到那个位置可以成功输出结果就可以
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int T;
void solve()
{
int n, k;
cin >> n >> k;
int sum = 0;
vector<int> a(n), s(n);
for(int i = 0;i < n;i ++){
cin >> a[i];
sum += a[i];
if(!i) s[i] = a[i];
else s[i] = s[i - 1] + a[i];
}
if(n == 1){
cout << 1 << endl;
return;
}
sort(a.begin(), a.end(), greater());
int ans = 0, cur = 0;
for(int i = 0;i < n;i ++){
if(a[i] - 1 + cur >= k * (n - i - 1)){
cout << ans + 1 + max(0, k * (n - i - 1) - cur) << '\n';
return;
}
ans += a[i], cur += a[i] - 1;
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> T;
while(T --){
solve();
}
return 0;
}
K

转化题目意思,点心mod4不能等于1,那么可以直接对a数组进行取模4。首先1这个数很不好,必须先全部干掉,组合有31和211。如果干不掉就输出-1。其次3这个数也不好,连续3个3就不能成立了,并且32也不能成立,那么用332去干掉3。不行就输出-1。2和4(也就是取模后的0)这两个数无所谓,最后可以连续或者怎么放都可以
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int T;
void solve()
{
int n;
cin >> n;
queue<int> q[4];
vector<int> ans;
for(int i = 0, x;i < n;i ++){
cin >> x, x %= 4;
q[x].push(i + 1);
}
//3 1
while(!q[3].empty() && !q[1].empty()){
int three = q[3].front(), one = q[1].front();
q[3].pop(), q[1].pop();
ans.push_back(three);
ans.push_back(one);
}
//2 1 1
while(q[1].size() >= 2 && !q[2].empty()){
int one1 = q[1].front(), two = q[2].front();
q[2].pop(), q[1].pop();
int one2 = q[1].front();
q[1].pop();
ans.push_back(two);
ans.push_back(one1);
ans.push_back(one2);
}
if(!q[1].empty()){
cout << -1 << endl;
return;
}
//3 3 2
while(q[3].size() >= 2 && !q[2].empty()){
int three1 = q[3].front(), two = q[2].front();
q[3].pop(), q[2].pop();
int three2 = q[3].front();
q[3].pop();
ans.push_back(three1);
ans.push_back(three2);
ans.push_back(two);
}
if(!q[3].empty()){
cout << -1 << endl;
return;
}
while(!q[2].empty()){
auto two = q[2].front();
q[2].pop();
ans.push_back(two);
}
while(!q[0].empty()){
auto zero = q[0].front();
q[0].pop();
ans.push_back(zero);
}
for(auto x : ans)
cout << x << " ";
cout << '\n';
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> T;
while(T --){
solve();
}
return 0;
}
G

思维题,必须想到对3取模不然一直出不来。如果mod3 == 0直接输出答案,mod3 == 1那么必须有两个3和其组合变成7输出ans - 1,如果没有两个以上的3就直接输出-1,mod3 == 2那么必须有一个3和其组合变成5,没有就-1
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int T;
void solve()
{
int n;
cin >> n;
int ans = n / 3;
n %= 3;
if(n == 0) cout << ans << endl;
else if(n == 1){
if(ans >= 2) cout << ans - 1 << endl;
else cout << -1 << endl;
}else{
if(ans >= 1) cout << ans << endl;
else cout << -1 << endl;
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> T;
while(T --){
solve();
}
return 0;
}
签到题这里就不写了。
最后还是有点遗憾,水平不够,H题没开出来,C题的线段树也写不了
1900

被折叠的 条评论
为什么被折叠?



