蓝桥杯第十四届模拟赛 最小下标

记录一下循环开始的下标,比较时如果读到尾,则将索引转换到下标。

#include <iostream>
#include <cstring>
#include <cctype>
#include <vector>

using namespace std;

typedef long long LL;

const int N = 1e6 + 10;

int idx;
char b[N];
int a[256];

vector<int> step;

string c, unit;

int st[N];


struct node {
	vector<int> a;
	int flag, id;	
};


bool cmp(node a, node c) {
	int len = min(a.a.size(), c.a.size());
	if (a.flag == c.flag && a.a.size() == c.a.size()) {
		bool flag1 = true;
		for (int i = 0; i < a.a.size(); i ++) {
			if (b[a.a[i]] != b[c.a[i]]) {
				flag1 = false;	
				break;
			}	
		}
		if (flag1) return false;
	}
	for (int i = 0, j = 0; i < len; i ++, j ++) {
		if (i >= a.a.size()) i = a.flag;
		else if (j >= c.a.size()) j = c.flag;
		if (b[a.a[i]] != b[c.a[j]]) {
			if (b[a.a[i]] < b[c.a[j]])
				return true;
			else
				return false;
		}	
	}
	return false;
}




int main() {
	a['A'] = 1, a['B'] = 2, a['C'] = 3, a['D'] = 4, a['E'] = 5, a['F'] = 6;
	cin >> b;
	int len = (int) strlen(b);

	int lflag = 0;
	string last;

	node mx1;
	for (int i = 0; i < len; i ++) {
		c.clear();
		memset(st, -1, sizeof st);
		int idx = i;
		node now;
		now.id = i;

		while (true) {
			now.a.push_back(idx);
			if (st[idx] != -1) {
				now.flag = st[idx];	
				// for (int i = 0; i < now.a.size(); i ++) {
				// 	cout << b[now.a[i]];
				// }
				// cout << "\n" << now.flag << endl;
				break;
			}
			st[idx] = true;
			c.push_back(b[idx]);
			idx += a[b[idx]];
			if (idx >= len) {
				idx %= len;
			}
	    }
	    if (i == 0) {
	    	mx1 = now;
	    } else {
	    	if (cmp(now, mx1) == true) {
	    		mx1 = now;
	    	}
	    }
	}
	cout << mx1.id;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值