无聊的活动/缘生意转(2018 Nova OJ新年欢乐赛B题)解题报告

题目2(下面的太抓 我重新写了个背景 其他都一样)

无聊的活动

JLZ老师不情愿的参加了古风社一年一度的活动,他实在不觉得一群学生跳舞有什么好看,更不明白坐在身后的学生为什么这么兴奋(看小姐姐),于是露出了相当无聊+严肃的表情。
  这不公平!因为他旁边的XBS老师是机器人!真正的XBS,在办公室里睡觉!
  不过,他有一个艰巨的任务!那就是!做游戏!
  这里的歌词有好多都带数字,比如“二十四桥明月不若此时节”、“三五各掌花灯盈盈各眉眼”,X老师把歌词翻译成英文,再由机器人筛选并翻译成阿拉伯数字。
  现在机器人XBS会挑出含义为小于100的自然数的单词,并将答案加上该数。其余单词均表示0。
  如果不这样做,机房的孩子就不能考试了!(╯‵□′)╯︵┻━┻

 #include<cstdio>
#include<cstring>
#include<map>
#include<string>
#include<iostream>
#include<algorithm>
#include<ctime>
using namespace std;
int n,ans,len,val,list[][];
char s[];
char dic[][]={"one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty","twenty-one","twenty-two","twenty-three","twenty-four","twenty-five","twenty-six","twenty-seven","twenty-eight","twenty-nine","thirty","thirty-one","thirty-two","thirty-three","thirty-four","thirty-five","thirty-six","thirty-seven","thirty-eight","thirty-nine","forty","forty-one","forty-two","forty-three","forty-four","forty-five","forty-six","forty-seven","forty-eight","forty-nine","fifty","fifty-one","fifty-two","fifty-three","fifty-four","fifty-five","fifty-six","fifty-seven","fifty-eight","fifty-nine","sixty","sixty-one","sixty-two","sixty-three","sixty-four","sixty-five","sixty-six","sixty-seven","sixty-eight","sixty-nine","seventy","seventy-one","seventy-two","seventy-three","seventy-four","seventy-five","seventy-six","seventy-seven","seventy-eight","seventy-nine","eighty","eighty-one","eighty-two","eighty-three","eighty-four","eighty-five","eighty-six","eighty-seven","eighty-eight","eighty-nine","ninety","ninety-one","ninety-two","ninety-three","ninety-four","ninety-five","ninety-six","ninety-seven","ninety-eight","ninety-nine"};
int check()
{
len=strlen(s),val=len+((s[]-'a')<<)+((s[len-]-'a')<<);
for(int i=;i<=list[val][];++i){
for(int j=;j<len;++j){
if(s[j]!=dic[list[val][i]][j]) break;
if(j==len-) return list[val][i]+;
}
}
return ;
}
void init()
{
for(int i=;i<;++i){
len=strlen(dic[i]);
val=len+((dic[i][]-'a')<<)+((dic[i][len-]-'a')<<);
list[val][++list[val][]]=i;
}
}
int main()
{
freopen("numstring10.in","r",stdin);
freopen("numstring10.out","w",stdout);
//int st=clock();
init();
cin>>n;
for(int i=;i<=n;++i){
scanf("%s",s);
ans+=check();
}
cout<<ans<<endl;
//cout<<clock()-st;
return ;
}

  由于学校的评测机太过缓慢,这道当时唯一没有出锅的题出锅了,逼我不得不重新写了个更快的哈希。原来以字符串长度为分类来查找,现在是字符串长度+首字母+尾字母,本人已经尽力。

——————————分割线——————————

题目

无聊的活动/缘生意转(2018 Nova OJ新年欢乐赛B题)解题报告

无聊的活动/缘生意转(2018 Nova OJ新年欢乐赛B题)解题报告

无聊的活动/缘生意转(2018 Nova OJ新年欢乐赛B题)解题报告

写在前面

好像是网络问题导致我无法在电脑上看评测记录,不过根据Wahacer dalao发来的截图……

无聊的活动/缘生意转(2018 Nova OJ新年欢乐赛B题)解题报告

无聊的活动/缘生意转(2018 Nova OJ新年欢乐赛B题)解题报告

这些画风清奇的打表已经完美诠释了什么叫暴力美学(噗)。

其实也没关系,因为本题的正解就是暴力+优hu化gao,由于要面向新高一同学就出的比较水(然而真相是我想不出来难题)。

正文

最初的想法是,把难点设在构造1-99的单词上,直接塞进map就做完了,了解一下构造方法。

 #include<cstdio>
#include<map>
#include<ctime>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
map<string,int>mp;
int n,ans;
string tmp;
char s[];
string I[]={"","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve"};
string II[]={"twen","thir","four","fif"};
void trans(){if(tmp[]=='e') tmp.erase(tmp.size()-,tmp.size());}
void init()
{
for(int i=;i<=;++i) mp[I[i]]=i;
for(int i=;i<=;++i){
tmp=(i<=?II[i-]:I[i-]);
trans();
mp[tmp+"teen"]=i;
}
II[]="for";
for(int i=;i<=;++i){
tmp=(i<=?II[i-]:I[i]);
trans();
tmp+="ty";
mp[tmp]=i*;
for(int j=;j<=;++j) mp[tmp+"-"+I[j]]=i*+j;
}
}
int main()
{
//freopen("numstring10.in","r",stdin);
//int st=clock();
init();
cin>>n;
while(n--){
scanf("%s",s);
tmp=string(s);
ans+=mp[tmp];
}
cout<<ans<<endl;
//cout<<clock()-st;
return ;
}

大致思路是把要用的部分打一个小小的表然后就可以构造十几和几十几的单词了,很简单吧。特别注意eighty的t要去掉一个(程序中的trans函数);构造“几十”之前把“four”变成“for”。(果然是考察小学英语)

不过鉴于很多高一的同学还没有学map,下面70分暴力先了解一下——

 #include<cstdio>
#include<cstring>
#include<map>
#include<string>
#include<iostream>
#include<algorithm>
#include<ctime>
using namespace std;
int n,ans;
char s[];
char dic[][]={"one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty","twenty-one","twenty-two","twenty-three","twenty-four","twenty-five","twenty-six","twenty-seven","twenty-eight","twenty-nine","thirty","thirty-one","thirty-two","thirty-three","thirty-four","thirty-five","thirty-six","thirty-seven","thirty-eight","thirty-nine","forty","forty-one","forty-two","forty-three","forty-four","forty-five","forty-six","forty-seven","forty-eight","forty-nine","fifty","fifty-one","fifty-two","fifty-three","fifty-four","fifty-five","fifty-six","fifty-seven","fifty-eight","fifty-nine","sixty","sixty-one","sixty-two","sixty-three","sixty-four","sixty-five","sixty-six","sixty-seven","sixty-eight","sixty-nine","seventy","seventy-one","seventy-two","seventy-three","seventy-four","seventy-five","seventy-six","seventy-seven","seventy-eight","seventy-nine","eighty","eighty-one","eighty-two","eighty-three","eighty-four","eighty-five","eighty-six","eighty-seven","eighty-eight","eighty-nine","ninety","ninety-one","ninety-two","ninety-three","ninety-four","ninety-five","ninety-six","ninety-seven","ninety-eight","ninety-nine"};
int check()
{
for(int i=;i<;++i){
//int len1=strlen(s),len2=strlen(dic[i]);
//if(len1!=len2) continue;
for(int j=;j<len1&&j<len2;++j){
if(s[j]!=dic[i][j]) break;
if(j==len1-) return i+;
}
}
return ;
}
int main()
{
//freopen("numstring10.in","r",stdin);
//int st=clock();
cin>>n;
for(int i=;i<=n;++i){
scanf("%s",s);
ans+=check();
}
cout<<ans<<endl;
//cout<<clock()-st;
return ;
}

如果我们打表了但只写暴力查找就会被3e6的范围卡掉。

真·标程了解一下——

 #include<cstdio>
#include<cstring>
#include<map>
#include<string>
#include<iostream>
#include<algorithm>
#include<ctime>
using namespace std;
int n,ans,len,list[][];
char s[];
char dic[][]={"one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty","twenty-one","twenty-two","twenty-three","twenty-four","twenty-five","twenty-six","twenty-seven","twenty-eight","twenty-nine","thirty","thirty-one","thirty-two","thirty-three","thirty-four","thirty-five","thirty-six","thirty-seven","thirty-eight","thirty-nine","forty","forty-one","forty-two","forty-three","forty-four","forty-five","forty-six","forty-seven","forty-eight","forty-nine","fifty","fifty-one","fifty-two","fifty-three","fifty-four","fifty-five","fifty-six","fifty-seven","fifty-eight","fifty-nine","sixty","sixty-one","sixty-two","sixty-three","sixty-four","sixty-five","sixty-six","sixty-seven","sixty-eight","sixty-nine","seventy","seventy-one","seventy-two","seventy-three","seventy-four","seventy-five","seventy-six","seventy-seven","seventy-eight","seventy-nine","eighty","eighty-one","eighty-two","eighty-three","eighty-four","eighty-five","eighty-six","eighty-seven","eighty-eight","eighty-nine","ninety","ninety-one","ninety-two","ninety-three","ninety-four","ninety-five","ninety-six","ninety-seven","ninety-eight","ninety-nine"};
int check()
{
len=strlen(s);
for(int i=;i<=list[len][];++i){
for(int j=;j<len;++j){
if(s[j]!=dic[list[len][i]][j]) break;
if(j==len-) return list[len][i]+;
}
}
return ;
}
void init()
{
for(int i=;i<;++i){
len=strlen(dic[i]);
list[len][++list[len][]]=i;
}
//for(int i=1;i<=20;++i) printf("%d %d\n",i,list[i][0]);
}
int main()
{
//freopen("numstring10.in","r",stdin);
//freopen("disappear.out","w",stdout);
//int st=clock();
init();
cin>>n;
for(int i=;i<=n;++i){
scanf("%s",s);
ans+=check();
}
cout<<ans<<endl;
//cout<<clock()-st;
return ;
}

  打表的部分参考前一个程序,这里的优化是把字符串根据长度分类,这样只用查找相同长度的目标串,可以水到100,灵感来源于哈希值,这里的len==key(这道题顺便为没学哈希的同学打一点基础)。当然我也了解到可以用“-”作为分割线,这样查找范围变小了好多;然后好像有写strcmp胡搞过的(???)等等(不管啦 反正就是个暴力题)。

写在后面

  第一次出题没有什么经验,而且比较水,搞了好久才弄完善。冬令营把题面搞出来,回家才学会出数据,这个解题报告就拖到开学了(中间还经历了一段痛苦不堪的补gan作业)。感谢Wahacer把最佳出题人赏赐给小的QAQ 有点承受不起啊(毕竟题这么水)……

  12mango退役快乐~~~

上一篇:POJ 1739


下一篇:冲刺Noip2017模拟赛2 解题报告——五十岚芒果酱