我做的G、H的解题报告。。。
G:
给定一个字符串,按特定的规则将其改写。。
规则就是:
1)将某些特定的词组换成特定的词组,他们是:
(2)判断s是short的方式:
(1):如果s后面接的是b,k,f或者其他非字母的东东,那他就是short的
(2):如果sss的话那么中间的s是short的,其他的是long的。
(3)尽可能“长”,比方出现ssst,那么输出就是[longs]s[longst];
明白了题目的意思那么就是纯粹的模拟题,注意模拟的完整性和正确,小心一点;
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define DOR(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define oo 1<<30
#define eps 1e-8
#define nMax 5000
#define pb push_back
#define bug puts("OOOOh.....");
#define zero(x) (((x)>0?(x):-(x))<eps)
char s[nMax];
string ans;
int l;
void go(int &i){
if(s[i]=='A' && i+1<l && (s[i+1]=='E'||s[i+1]=='e')) { ans+="[AE]";i+=2;return ;}
if(s[i]=='a' && i+1<l && s[i+1]=='e') { ans+="[ae]";i+=2;return ;}
if(s[i]=='a' && i+1<l && s[i+1]=='E') { ans+="[AE]";i+=2;return ;}
if(s[i]=='O' && i+1<l && (s[i+1]=='E'||s[i+1]=='e')) {ans+="[OE]";i+=2;return ;}
if(s[i]=='o' && i+1<l && s[i+1]=='e') {ans+="[oe]";i+=2;return ;}
if(s[i]=='o' && i+1<l && s[i+1]=='E') {ans+="[OE]";i+=2;return ;}
if(i+1<l) {
if(s[i]=='c'&&s[i+1]=='t') {ans+="[ct]";i+=2;return ;}
if(s[i]=='f'){
if(s[i+1]=='l'||s[i+1]=='i') { ans+="[";ans+=s[i];ans+=s[i+1];ans+="]";i+=2;return ;}
if(s[i+1]=='f' && (i+2>=l||s[i+2]!='i'&&s[i+2]!='l')) { ans+="[";ans+=s[i];ans+=s[i+1];ans+="]";i+=2;return ;}
}
}
if(i+2<l) {
if(s[i]=='f' && s[i+1]=='f'){
if(s[i+2]=='i'||s[i+2]=='l') {ans+="[";ans+=s[i];ans+=s[i+1];ans+=s[i+2];ans+="]";i+=3;return ;}
}
}
if(s[i]=='s'){
if(i+1>=l || (s[i+1]<'A'||s[i+1]>'Z'&&s[i+1]<'a'||s[i+1]>'z') || s[i+1]=='b' || s[i+1]=='f' || s[i+1]=='k') {ans += "s";i+=1;return ;}
else {
ans += "[longs";
if(s[i+1]=='i'||s[i+1]=='h'||s[i+1]=='l'||s[i+1]=='t') {ans+=s[i+1];ans+="]";i+=2;return ;}
if(s[i+1]=='s'){
if(i+2<l && s[i+2]=='s'){
if(i+3>=l || (s[i+3]<'A'||s[i+3]>'Z'&&s[i+3]<'a'||s[i+3]>'z') || s[i+3]=='b' || s[i+3]=='f' || s[i+3]=='k'){
ans += "s]";
i+=2;
return ;
}
ans += "]s";
i+=2;
return ;
}
if(i+2<l && s[i+2]=='i'){
ans += "si]";
i+=3;
return ;
}
if(i+2>=l || (s[i+2]<'A'||s[i+2]>'Z'&&s[i+2]<'a'||s[i+2]>'z') || s[i+2]=='b' || s[i+2]=='f' || s[i+2]=='k'){
ans += ']';
i += 1;
return ;
}
ans += "s]";
i += 2;
return ;
}
ans += "]";
i+=1;
return ;
}
}
//printf("---%d %c\n",i,s[i]);
ans += s[i];
i+=1;
return ;
}
int main(){
//freopen("input.txt","r",stdin);
int t,cas;
scanf("%d",&t);
while(t--){
scanf("%d ",&cas);
gets(s);
int i=0;
l=strlen(s);
ans="";
while(i<l){
go(i);
}
printf("%d %s\n",cas,ans.c_str());
}
return 0;
}
H:
题目大意就是条形码的基本结构是SLLLLLLMRRRRRRE
其中S和E都是三位二进制编码 固定为101
M为五位二进制编码 固定为01010
L和R都是七位二进制编码,各有十中可能对于不同的值,如下
:
6个L和6个R对应的值构成12个数值;
一个合法的条形码满足:
CheckSum = 3*(digit1 + digit3 + digit5 + digit7 +digit9 + digit11) + digit2 + digit4 +digit6 + digit8 + digit10.
Code = CheckSum Mod(10);
If Code = 0, check digit = 0. Other wise, check digit= (10 – Code).
Code = CheckSum Mod(10);
If Code = 0, check digit = 0. Other wise, check digit= (10 – Code).
并且check digit = digit12
现在给你95个二进制编码,其中有些’?’表示可以是0也可以是1的。
这个二进制也可以倒着看,问你组成合法的条形码有多少种,并将这些12个值组成的条形码按从小到大的顺序输出。
我们用c[i] 表示第i个数可能是多少,然后枚举,判断是否可以组成合法的条形码。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define DOR(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define oo 1<<30
#define eps 1e-8
#define nMax 500
#define pb push_back
#define bug puts("OOOOh.....");
#define zero(x) (((x)>0?(x):-(x))<eps)
char s[nMax];
char L[][10]={"0001101","0011001","0010011","0111101","0100011","0110001","0101111","0111011","0110111","0001011"};
char R[][10]={"1110010","1100110","1101100","1000010","1011100","1001110","1010000","1000100","1001000","1110100"};
int check(char u[],char v[]){
for(int i=0;u[i];i++){
if(u[i]!=v[i]&&v[i]!='?') return 0;
}
return 1;
}
vector<int> c[20];
int OK(int f[]){
int ans=0;
for(int i=0;i<11;i+=2) ans+=3*f[i];
for(int i=1;i<11;i+=2) ans+=f[i];
ans %= 10;
if(ans) ans = 10-ans;
//printf("%d %d\n",ans,f[11]);
if(ans == f[11]) return 1;
return 0;
}
int siz;
set<vector<int> > ans;
vector<int> change(int f[]){
return vector<int>(f,f+12);
}
void dfs(int i,int f[]){
if(i==12){
if(OK(f)){
ans.insert(change(f));
siz ++;
}
return ;
}
if(siz>=9) return ;
for(int j=0;j<c[i].size();j++) {
f[i]=c[i][j];
dfs(i+1,f);
if(siz>=9) return ;
}
return ;
}
int f[100];
char S[]={"101"};
char M[]={"01010"};
int GGG(char s[]){
for(int i=0;i<3;i++) if(s[i]!='?' && s[i]!=S[i]) return 0;
for(int i=0;i<3;i++) if(s[94-i]!='?' && s[94-i]!=S[i]) return 0;
for(int i=0;i<5;i++) if(s[45+i]!='?' && s[45+i]!=M[i]) return 0;
return 1;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
#endif
int t,cas;
scanf("%d",&t);
while(t--){
scanf("%d%s%s",&cas,s,s+50);
//printf("%d\n",strlen(s));
int tmp=0;
for(int i=3;i<=44;i+=7){
c[tmp].clear();
for(int j=0;j<10;j++) if(check(L[j],s+i)) c[tmp].pb(j);
//cout<<c[tmp].size()<<endl;
tmp++;
}
for(int i=50;i<=95;i+=7){
c[tmp].clear();
for(int j=0;j<10;j++) if(check(R[j],s+i)) c[tmp].pb(j);
//cout<<c[tmp].size()<<endl;
tmp++;
}
ans.clear();
siz=0;
if(GGG(s))
dfs(0,f);
for(int i=0;i<47;i++) swap(s[i],s[94-i]);
tmp=0;
for(int i=3;i<=44;i+=7){
c[tmp].clear();
for(int j=0;j<10;j++) if(check(L[j],s+i)) c[tmp].pb(j);
//cout<<c[tmp].size()<<endl;
tmp++;
}
for(int i=50;i<=95;i+=7){
c[tmp].clear();
for(int j=0;j<10;j++) if(check(R[j],s+i)) c[tmp].pb(j);
//cout<<c[tmp].size()<<endl;
tmp++;
}
if(GGG(s))
dfs(0,f);
printf("%d %d\n",cas,siz);
set<vector<int> >::iterator it = ans.begin();
for(int i=0;i<min(8,(int)ans.size());i++) {
for(int j=0;j<((*it).size());j++) printf("%d",(*it)[j]);
printf("\n");
it++;
}
}
return 0;
}