Minimum palindrome

Hit the table to find the law!
Difficulties in the law of 2 m ==, violence hit the table is very important.
AC Code (15ms):

/*代码没注释,回看两行泪*/
#include <functional>
#include <algorithm>
#include <stdexcept>
#include <iostream>
#include <sstream>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <cctype>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <queue>
#include <stdio.h>
#include <stack>
#include <ctime>
#include <list>
#include <map>
#include <set>
#include <assert.h>
#define fill(x,c) memset(x,c,sizeof(x))
using namespace std;
typedef long long ll;
int t;
string sum(int n,char c){
	if(n<=0)	return "";
	string ans;
	for(int i=0;i<n;i++)	ans+=c;
	return ans;
}
string solve(int m,int n){
	if(m==1){
		return sum(n,'a');
	}else if(m==2){
		string res;
            vector<string> ans={"" ,
						   		"a",
								"ab",
								"aab" ,
								"aabb",
								"aaaba" ,
								"aaabab",
								"aaababb",
								"aaababbb",
								"aaaababba",
								"aaaababbaa",
								"aaaababbaaa",
								"aaaababbaaaa"};
	        if(n<13)	return ans[n];
	        res = "aaaa";
			string base = "babbaa";
			int num = (n-4)/6;
			 int ys = (n-4)%6 ;
			 for(int i=0;i<num;i++){
				res+=base;
			}
			res+=base.substr(0,ys);
			return res;
		
	}else{
			int num_abc = n/3;
			int ys = n%3;
			string res;
			string base = "abc";
			for(int i=0;i<num_abc;i++){
				res+=base;
			}
			res+=base.substr(0,ys);
			return res;
		}
}
int main(){
	
	cin>>t;
	int m,n,cnt=1;
	while(t--){
		cin>>m>>n;
		string res = solve(m,n); 
		cout<<"Case #"<<cnt<<": "<<res<<endl;
		cnt++;
	} 
	return 0;
}

Guess you like

Origin blog.csdn.net/Csdn_jey/article/details/92012857