敌我双方都放进数组,排序,对q == 0、1、2的情况依次分类讨论,简单粗暴,无脑AC。

#include <iostream>
#include <algorithm>

using namespace std;

const int N = 20;

int a[N];

void solve() {
	int m, n, q; cin >> m >> n >> q;
	for(int i = 0; i < m + n; i++) cin >> a[i];
	if(q == 0) {
		cout << "GG" << endl;
	}
	else if(q == 1) {
		sort(a, a + m + n);
		if(a[0] != 1) {
			cout << "GG" << endl;
			return;
		}
		for(int i = 1; i < m + n; i++) {
			if(a[i] - a[i - 1] > 1) {
				cout << "GG" << endl;
				return;
			}
		}
		cout << "Legendary" << endl;
	}
	else {
		sort(a, a + m + n);
		if(a[0] > 2) {
			cout << "GG" << endl;
			return;
		}
		else if(a[0] == 2) {
			for(int i = 1; i < m + n; i++) {
				if(a[i] - a[i - 1] > 1) {
					cout << "GG" << endl;
					return;
				}
			}
			cout << "Legendary" << endl;
			return; 
		}
		int f = 0; 
		for(int i = 1; i < m + n; i++) {
			if(a[i] - a[i - 1] == 2) {
				if(!f) f = 1;
				else {
					cout << "GG" << endl;
					return;
				}
			}
			else if(a[i] - a[i - 1] > 2) {
				cout << "GG" << endl;
				return;
			}
			
		}
		cout << "Legendary" << endl;
	}
}

int main() {
	int T; cin >> T;
	while(T--) {
		solve();
	}
	
	return 0;
}

全部评论

相关推荐

qq乃乃好喝到咩噗茶:院校后面加上211标签,放大加粗,招呼语也写上211
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务