BestCoder #37 Rikka with string (hdu 5205)

2 篇文章 0 订阅
// 这题一开始看的时候觉得就是取最右边的问号,依次从大到小枚举
// 注意没有?和?在中间的情况特判,结果wa了十一发,还是没有找到
// 错误在哪里,看了一下discuss里面的数据发现5 b??ab这组用我先开始
// 的思路是跪了的。我的会输出QwQ。。。
//
// 然后看了看大牛们的思路,发现自己所谓的最右边是错的,这题要求字典序最小
// 可以先全部把?填成a,判断是否回文,
// 如果不是回文直接输出,
// 如果是回文,那么我们可以直接把最右边的不是中间的填成b,输出就好了
// 这是第二种的做法
// 
// 还有一种就是爆搜,分情况讨论,发现爆搜的魅力是如此的强大,我要学爆搜啦
// 555,哎,就其原因,还是自己太水了,
// 今天听到大牛的一句话,没有ac不了的题目,只有懒惰的acmer
// 继续练吧。。。。

// 第一次的代码是错误的,只是留着作为惊醒,望多多原谅

//const int maxn = 1008;
//char s[maxn];
//int n;
char ch[maxn];
//int mark;
//int cnt;
//bool isp(char* s){
//	for (int i=0;i<n/2;i++)
//		if (s[i]!=s[n-1-i])
//			return false;
//	return true;
//}
//
//bool get(){
//	for (int i=0;i<26;i++){
//		s[mark] = i + 'a';
//		if (!isp(s)){
//			puts(s);
//			return true;
//		}
//	}
//	return false;
//}
//
//void solve(){
//	mark = -1 ;
//	for (int i=0;i<n;i++)
//		if (s[i]=='?'){
//			mark = i;
//		}
//	for (int i=0;i<n;i++)
//		if (s[i]=='?'){
//			s[i] = 'a';
//		}
//	//puts(s);
//	if (mark==-1){
//		if (isp(s))
//			puts("QwQ");
//		else
//			puts(s);
//	}
//	else {
//		if (isp(s)&&mark==n/2&&n%2!=0){
//			puts("QwQ");
//			return ;
//		}
//		bool flag = get();
//	}
//}
//
//int main() {
//    freopen("G:\\Code\\1.txt","r",stdin);
//	while(scanf("%d",&n)!=EOF){
//		scanf("%s",s);
//		solve();
//	}
//	return 0;
//}



//#include <algorithm>
//#include <bitset>
//#include <cassert>
//#include <cctype>
//#include <cfloat>
//#include <climits>
//#include <cmath>
//#include <complex>
//#include <cstdio>
//#include <cstdlib>
//#include <cstring>
//#include <ctime>
//#include <deque>
//#include <functional>
//#include <iostream>
//#include <list>
//#include <map>
//#include <numeric>
//#include <queue>
//#include <set>
//#include <stack>
//#include <vector>
//#define ceil(a,b) (((a)+(b)-1)/(b))
//#define endl '\n'
//#define gcd __gcd
//#define highbit(x) (1ull<<(63-__builtin_clzll(x)))
//#define popcount __builtin_popcountll
//typedef long long ll;
//using namespace std;
//const int mod = 1000000007;
//const long double pi = acos(-1.l);
//
//template<class t> inline t lcm(const t& a, const t& b) { return a/gcd(a, b)*b; }
//template<class t> inline t lowbit(const t& x) { return x&-x; }
//template<class t> inline t maximize(t& a, const t& b) { return a=a<b?b:a; }
//template<class t> inline t minimize(t& a, const t& b) { return a=a<b?a:b; }
//
//const int maxn = 1008;
//char s[maxn];
//int n;
//
//bool isp(char* s){
//	for (int i=0;i<n/2;i++)
//		if (s[i]!=s[n-1-i])
//			return false;
//	return true;
//}
//
//
//void init(){
//	scanf("%s",s);
//}
//
//void solve(){
//	vector<int> v;
//	for (int i=0;i<n;i++)
//		if (s[i]=='?'){
//			s[i]='a';
//			v.push_back(i);
//		}
//	if (!isp(s))	puts(s);
//	else {
//		bool flag = false;
//		for (int i=v.size()-1;i>=0;i--){
//			if (!(v[i]==n/2&&(n&1)==1)){
//				s[v[i]] = 'b';
//				flag = true;
//				break;
//			}
//		}
//		if (flag)	puts(s);
//		else puts("qwq");
//	}
//}
//
//int main() {
//    freopen("g:\\code\\1.txt","r",stdin);
//	while(scanf("%d",&n)!=eof){
//		init();
//		solve();
//	}
//	return 0;
//}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define ceil(a,b) (((a)+(b)-1)/(b))
#define endl '\n'
#define gcd __gcd
#define highBit(x) (1ULL<<(63-__builtin_clzll(x)))
#define popCount __builtin_popcountll
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const long double PI = acos(-1.L);

template<class T> inline T lcm(const T& a, const T& b) { return a/gcd(a, b)*b; }
template<class T> inline T lowBit(const T& x) { return x&-x; }
template<class T> inline T maximize(T& a, const T& b) { return a=a<b?b:a; }
template<class T> inline T minimize(T& a, const T& b) { return a=a<b?a:b; }

const int maxn = 1008;
int n;
char s[maxn];
bool isp(char* s){
	for (int i=0;i<n/2;i++)
		if (s[i]!=s[n-1-i])
			return false;
	return true;
}

bool flag;

void dfs(int i){
	if (flag==true) return ;
	if (i==n){
		if (!isp(s)){
			puts(s);
			flag = true;
		}
		return ;
	}
	if (s[i]>='a'&&s[i]<='z'){
		dfs(i+1);
	}
	else{
		for (int j=0;j<26;j++){
			s[i] =j + 'a';
			dfs(i+1);
			s[i] = '?';
		}
	}
}

void init(){
	scanf("%s",s);
	flag = false;
}

void solve(){
	dfs(0);
	if (!flag)
		puts("QwQ");
}

int main() {
    freopen("g:\\code\\1.txt","r",stdin);
	while(scanf("%d",&n)!=EOF){
		init();
		solve();
	}
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值