思路:当一个人的战力大于等于最大的人的战力,那么肯定可以留下,因为打赢一次,战力乘2,所以最多赢31次就可以肯定他可以留下(隐含条件)
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
const int maxn = 1e6 + 5, inf = 1e18;
int a[maxn];
string s;
int n;
map<int, int> mp;
void solve()
{
vector<int> ans;
cin >> n;
int maxx = 0;
for(int i = 0; i < n; i++){
cin >> a[i];
maxx = max(maxx, a[i]);
// a[i + n] = a[i];
}
for(int i = 0; i < n; i++){
int l = i - 1, r = i + 1;
int now = a[i];
bool win = 0;
for(int j = 0; j <= 32; j++){
while(l >= 0 && now >= a[l] && now < maxx){
now *= 2;
l = l - 1;
}
while(r <= n - 1 && now >= a[r] && now < maxx){
now *= 2;
r = r + 1;
}
if(now >= maxx){
win = 1;
break;
}
}
if(win) ans.pb(i + 1);
}
cout << ans.size() << '\n';
for(auto x : ans) cout << x << " \n"[x == ans.back()];
// cout << "\n";
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
// cin >> T;
while (T--)
{
solve();
}
return 0;
}
本文描述了一个编程问题,涉及计算在一场战力翻倍的比赛中,如何通过最少的操作次数确保某人在对抗最强对手时能留下。使用C++实现的算法通过递归和动态规划找到解决方案。
1164

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



