HDU 3363 冰糖葫芦

时间:2019-09-23
本文章向大家介绍HDU 3363 冰糖葫芦,主要包括HDU 3363 冰糖葫芦使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
#include <iostream>
using namespace std;

int main()
{
	int n;
	char c[100005];
	int	 cn[100005];
	while (cin >> n && n != 0) {
		int h= 0;
		int t = 0;
		cin >> c;
		if (n % 2 != 0) {
			cout << -1<< endl;
			continue;
		}
		else
		{
			for (int i = 0; i < n; i++) {
				if (c[i] == 'H') {
					h++;
					
				}
				else
				{
					t++;
				}
				cn[i] = h;
			}
			if (h % 2 != 0 || t % 2 != 0) {
				cout << -1 << endl;
				continue;
			}
			int hh = 0;
			for (int i = 0; i < n / 2; i++) {
				if (c[i] == 'H') hh++;
			}
			if (hh == h / 2) {
				cout << 1 << "\n" << n / 2 << endl;
				continue;
			}
			else
			{
				cout << 2 << endl;
			}
			
			for (int i = 0; i < n / 2 - 1; i++) {
				if (cn[i + n / 2] - cn[i] == h/2) {
					cout << i+1 << " " << i + n / 2+1 << endl;
					break;
				}
			}
		}
	}
	return 0;
}

原文地址:https://www.cnblogs.com/coegle18/p/11571648.html