题目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 ;
}

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

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

题目

写在前面

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

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

其实也没关系,因为本题的正解就是暴力+优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退役快乐~~~

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

  1. 2018年数学建模国赛B题 智能RGV的动态调度策略

    第一种情况大致思路: 每秒判断各个CNC的状态,若工作完成或者是出于空闲状态下则向RGV发出一个请求.同时,RGV每秒判断自己的状态(上下料.移动.闲置.清洗等),如果是处于闲置状态,则启用调度算法, ...

  2. 2018 ACM-ICPC徐州站网络赛 G题

    There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xxx , yy ...

  3. NOIP 2018 普及组 解题报告

    目录 标题统计 题目链接 思路 代码 龙虎斗 题目链接: 思路 代码 摆渡车 题目链接: 思路 对称二叉树 题目链接 思路: 先来解释一下为毛现在才来发解题报告: 其实博主是参加过NOIP 2018普 ...

  4. 【活动发布】捷微H5-微信新年砍价活动,开源发布了

    活动名称: 微信新年砍价 适用项目: 捷微H5活动平台源码下载:http://yun.jeecg.org/pmall/detail/924D63E4F73B4387B75DE9B8545136C5 视 ...

  5. 「九省联考 2018」IIIDX 解题报告

    「九省联考 2018」IIIDX 这什么鬼题,送的55分要拿稳,实测有60? 考虑把数值从大到小摆好,每个位置\(i\)维护一个\(f_i\),表示\(i\)左边比它大的(包括自己)还有几个数可以选 ...

  6. 华为2018软件岗笔试题之第一题python求解分享

    闲来无事,突然看到博客园首页上有人写了篇了华为2018软件岗笔试题解题思路和源代码分享.看了下题目,感觉第一题能做出来,就想着用刚刚学的python试着写一下,花费的时间有点长~~,看来又好长时间没练 ...

  7. 2018年高教社杯全国大学生数学建模竞赛D题解题思路

    题目 D题   汽车总装线的配置问题 一.问题背景 某汽车公司生产多种型号的汽车,每种型号由品牌.配置.动力.驱动.颜色5种属性确定.品牌分为A1和A2两种,配置分为B1.B2.B3.B4.B5和B6 ...

  8. 2018年高教社杯全国大学生数学建模竞赛C题解题思路

    题目 C题   大型百货商场会员画像描绘 在零售行业中,会员价值体现在持续不断地为零售运营商带来稳定的销售额和利润,同时也为零售运营商策略的制定提供数据支持.零售行业会采取各种不同方法来吸引更多的人成 ...

  9. 洛谷 T28312 相对分子质量【2018 6月月赛 T2】 解题报告

    T28312 「化学」相对分子质量 题目描述 做化学题时,小\(F\)总是里算错相对分子质量,这让他非常苦恼. 小\(F\)找到了你,请你来帮他算一算给定物质的相对分子质量. 如果你没有学过相关内容也 ...

随机推荐

  1. POJ2421Constructing Roads

    Constructing Roads Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 23343   Accepted: 10 ...

  2. BZOJ 1857: [Scoi2010]传送带

    二次联通门 : BZOJ 1857: [Scoi2010]传送带 /* BZOJ 1857: [Scoi2010]传送带 三分套三分 可能是吧..dalao们都说明显是一个单峰函数 可是我证不出来.. ...

  3. Day13:H5+JS+C3

    css布局中,什么是BFC BFC是Block formatting context的缩写,表示"块级格式化上下文". 设置BFC的元素,是一个独立的渲染区域,只有Block-le ...

  4. maven ssm 编译异常记录:

    maven ssm 编译异常记录: javax.servlet.jsp 解决: 清除 tomacat libraries 修改 pom 文件 <dependency> <groupI ...

  5. Java SpringBoot使用Redis缓存和Ehcache

    <?xml version="1.0" encoding="UTF-8"?> <ehcache xmlns:xsi="http:// ...

  6. zabbix与agent端通信加密

    Zabbix版本从3.0之后,开始支持Zabbix server, Zabbix proxy, Zabbix agent, zabbix_sender and zabbix_get之间的通信加密,加密 ...

  7. 深度学习面试题20:GoogLeNet(Inception V1)

    目录 简介 网络结构 对应代码 网络说明 参考资料 简介 2014年,GoogLeNet和VGG是当年ImageNet挑战赛(ILSVRC14)的双雄,GoogLeNet获得了第一名.VGG获得了第二 ...

  8. Flink 之 Data Source

    Data Sources 是什么呢?就字面意思其实就可以知道:数据来源. Flink 做为一款流式计算框架,它可用来做批处理,即处理静态的数据集.历史的数据集: 也可以用来做流处理,即实时的处理些实时 ...

  9. MQTT教學(二):安裝MQTT伺服器Mosquitto,Windows系統篇

    http://swf.com.tw/?p=1005 「認識MQTT」文章提到,MQTT的訊息全都透過稱為代理人(broker)的伺服器交流.本文將說明頗受歡迎的開放原始碼MQTT伺服器Mosquitt ...

  10. MQTT基础概念介绍

    https://blog.csdn.net/pipinet123/article/details/60866901 源博客地址:http://blog.csdn.net/pipinet123 MQTT ...