3.赢球票

题目链接:https://www.lanqiao.cn/problems/94/learning/?page=1&first_category_id=1&second_category_id=3

题意:

给定长度为n的卡片排列,顺时针从1开始数,若卡片上的数字与数的数字相同则将此卡片收入囊中,下一个卡片从头数
求最大的卡片数字和(可以从任意一张卡片开始)

set

求set最大值maxn=(*st.rbegin()),注意循环需要集合非空且数的数字要小于集合最大值!

#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define pb push_back
#define endl "\n"
#pragma GCC optimize(3)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const ll llmax=LLONG_MAX;
const int maxn=1e5+5;
const int mod=1e9+7;
int n;
int a[105];
set<int>st;
bool vis[105];
signed main()
{
	ios::sync_with_stdio(false),cin.tie(0);
	cin>>n;
	rep(i,1,n){
		cin>>a[i];
	}
	
	ll ans=0;
	rep(i,1,n){
		rep(j,1,n)st.insert(a[j]);
		rep(j,1,n)vis[j]=false;
		
		ll res=0;
		int t=1;
		int pos=i;
		while(!st.empty()&&t<=(*st.rbegin())){
			if(a[pos]==t&&!vis[pos]){
				res+=a[pos];
				st.erase(a[pos]);
				vis[pos]=true;
				t=1;
			}
			if(!vis[pos])t++;
			pos++;
			if(pos>n)pos=1;
		}
		ans=max(res,ans);	
	}
	cout<<ans;
	return 0;
}


posted @ 2025-02-18 18:31  Marinaco  阅读(19)  评论(0)    收藏  举报
//雪花飘落效果