题目链接:http://codeforces.com/contest/791/problem/C
题意:一个部队有n个人,然后按顺序1到k,2到k+1。。。。。n-k+1到n如果有重复名字,他会给你"NO",没有就给你"YES"。让你输出n个人的名字,使得符合要求。
分析:n最大50,于是我定义了string s[55],然后在里边存了50个不一样的英文名字,基本就是Aa,Ab这种的,然后开始构造,刚开始几个NO就输出几个一样的名字,当出现第一个YES的时候,输出不一样的名字,然后把名字数组下标记下来。如果接下来是NO,那就输入第前k-1个名字,如果是YES,那就继续输入一个不一样的名字。最后如果人数不够n,输出不同名字补齐即可。细节做好就行,慢慢调试QAQ(代码比较丑,勿看。)
AC代码:
1 #include<bits/stdc++.h> 2 using namespace std; 3 string s[100]={"","Aa","Ab","Ac","Ad","Ae","Af","Ag","Ah","Ai","Aj","Ak","Al","Am","An","Ao","Ap","Aq","Ar","As","At","Au","Av","Aw","Ax","Ay","Az", 4 "Ba","Bb","Bc","Bd","Be","Bf","Bg","Bh","Bi","Bj","Bk","Bl","Bm","Bn","Bo","Bp","Bq","Br","Bs","Bt","Bu","Bv","Bw","Bx","By","Bz" 5 "Ca","Cb","Cc","Cd","Ce","Cf","Cg","Ch","Ci","Cj","Ak","Al","Am","An","Ao","Ap","Aq","Ar","As","At","Au","Av","Aw","Ax","Ay","Az" 6 }; 7 int a[55]; 8 int main() { 9 ios_base::sync_with_stdio(0); 10 cin.tie(0); 11 int n,k; 12 string c[55]; 13 cin>>n>>k; 14 int j=1; 15 int number=1; 16 int p=0; 17 a[1]=1; 18 for(int i=1;i<=n-k+1;i++){ 19 cin>>c[i]; 20 if(i==1) cout<<s[1]; 21 if(c[i]=="NO"){ 22 if(c[i-1]=="YES"&&p==0){ 23 p=1; 24 for(int q=2;q<k;q++){ 25 j++; 26 number++; 27 a[number]=j; 28 cout<<" "<<s[j]; 29 } 30 number++; 31 cout<<" "<<s[a[number-k+1]]; 32 a[number]=a[number-k+1]; 33 } 34 else { 35 number++; 36 if(p==1) { 37 cout<<" "<<s[a[number-k+1]]; 38 a[number]=a[number-k+1]; 39 } 40 else { 41 if(number<k) { 42 cout<<" "<<s[a[number-1]]; 43 a[number]=a[number-1]; 44 } 45 else { 46 cout<<" "<<s[a[number-k+1]]; 47 a[number]=a[number-k+1]; 48 } 49 } 50 } 51 } 52 else{ 53 j++; 54 cout<<" "<<s[j]; 55 number++; 56 a[number]=j; 57 } 58 } 59 while(number<n){ 60 j++; 61 number++; 62 cout<<" "<<s[j]; 63 } 64 cout<<endl; 65 66 67 return 0; 68 }