BestCoder #37 Rikka with string (hdu 5205)

// 这题一开始看的时候觉得就是取最右边的问号,依次从大到小枚举
// 注意没有?和?在中间的情况特判,结果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;
}

时间: 2024-08-27 03:53:01

BestCoder #37 Rikka with string (hdu 5205)的相关文章

HDU 5202 Rikka with string (水DFS)

Rikka with string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 624    Accepted Submission(s): 243 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation

HDU - 5202 - Rikka with string (DFS)

Rikka with string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 214    Accepted Submission(s): 109 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation

HDU 6086 Rikka with String

Rikka with String http://acm.hdu.edu.cn/showproblem.php?pid=6086 题意: 求一个长度为2L的,包含所给定的n的串,并且满足非对称. 分析: AC自动机+状压dp. 首先给这个n个串,建立AC自动机.然后去枚举长度为L的一个串,就可以知道另一半了. 如果给定的串完全存在于左边或者右边,那么直接往AC自动机加入这个串或者取反后的反串.如果是跨越中间,那么暴力的把所有的串,从中间切开,然后判断是否合法,加入到AC自动机上就行,如果长度枚举

Rikka with string BC#37

Rikka with string Accepts: 395 Submissions: 2281 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 众所周知,萌萌哒六花不擅长数学,所以勇太给了她一些数学问题做练习,其中有一道是这样的: 有一天勇太得到了一个长度为n的字符串,但是六花一不小心把这个字符串搞丢了.于是他们想要复原这一个字符串.勇太记得这个字符串只包含小写字母而且这

hdu 5202 Rikka with string(模拟)

Rikka with string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 625    Accepted Submission(s): 244 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation

BestCoder Round #29 1003 (hdu 5172) GTY&#39;s gay friends [线段树 判不同 预处理 好题]

传送门 GTY's gay friends Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 264    Accepted Submission(s): 57 Problem Description GTY has n gay friends. To manage them conveniently, every morning he o

BestCoder Round #1 1001 &amp;&amp; 1002 hdu 4857 4858

hdu 4857 逃生 第一题是拓扑排序,不是按照字典序最小输出,而是要使较小的数排在最前面..赛后弄了好久,才比较明白,我一直以为 反向建图,i从1到n,开始深搜dfs( i ),对i点的边,由小到大继续搜一下,同时标记搜过的数,搜过之后就不再搜,搜到底之后ans[cnt++] = u;这样顺序输出就是答案,后来经过超哥指点,才明白深搜贪心是错的.只有 反向建图,用优先队列把较大的数尽量排在前面,然后反序输出才是正解.. 1 #include<iostream> 2 #include<

【bestcoder #37】ABC题解

Rikka with string Accepts: 395 Submissions: 2281 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 众所周知,萌萌哒六花不擅长数学,所以勇太给了她一些数学问题做练习,其中有一道是这样的: 有一天勇太得到了一个长度为n的字符串,但是六花一不小心把这个字符串搞丢了.于是他们想要复原这一个字符串.勇太记得这个字符串只包含小写字母而且这

[kuangbin带你飞]专题十六 KMP &amp; 扩展KMP &amp; ManacherK - Count the string HDU - 3336(前缀数量问题)

K - Count the string HDU - 3336 题目链接:https://vjudge.net/contest/70325#problem/K 题目: It is well known that AekdyCoin is good at string problems as well as number theory problems. When given a string s, we can write down all the non-empty prefixes of t