重 操 旧 业

陈志轩  •  5个月前


黄色的贪心很简单,直接暴力枚举输入的字符串两端的字符,两个不一样就选小的,一样就往中间搜,遇到不一样的就看在哪边就选哪边的字符,都一样就随便选。

#include<bits/stdc++.h>
using namespace std;
char s[500005],t[500005];
int cnt = 0;
signed main(){
	int n;
	cin>>n;
	for (int i = 1;i <= n;i++){
		cin>>s[i];
	}
	int l = 1,r = n;
	while (l <= r){
		if (s[l] < s[r]){
			cnt++;
			t[cnt] = s[l];
			l++;
		}
		else if (s[l] > s[r]){
			cnt++;
			t[cnt] = s[r];
			r--;
		}
		else{
			bool f = true;
			for (int i = l,j = r;i < j;i++,j--){
				if (s[i] < s[j]){
					cnt++;
					t[cnt] = s[l];
					l++;
					f = false;
					break;
				}
				else if (s[i] > s[j]){
					cnt++;
					t[cnt] = s[r];
					r--;
					f = false;
					break;
				}
			}
			if (f){
				cnt++;
				t[cnt] = s[l];
				l++;
			}
		}
	}
	for (int i = 1;i <= cnt;i++){
		cout<<t[i];
		if (i % 80 == 0){
			cout<<'\n';
		}
	}
	return 0;
}

那么金组的Best Cow Line怎么做呢?交上去只有 84 分,但是实践证明TLE的那个测试点里面输入的字符都是一样的,所以加特判就能直接AC

bool same = true;
for (int i = 1;i <= n;i++){
	cin>>s[i];
	if (i > 1 && s[i] != s[i - 1]){
		same = false;
	}
}
if (same){
	for (int i = 1;i <= n;i++){
		cout<<s[i];
		if (i % 80 == 0){
			cout<<'\n';
		}
	}
	return 0;
}

\color{white}又水了一道蓝题,我真nb


评论: