题目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. CODE FESTIVAL 2017 Final题解

    传送门 \(A\) 咕咕 const int N=55; const char to[]={"AKIHABARA"}; char s[N];int n; int main(){ s ...

  2. 在Modelsim波形中查看值

    在Modelsim的波形中查看值时,可以利用右键选择变量的数据类型.如果变量值为0,可以选择unsigned类型观察,可以1位显示0. 长度较大的数据以十六进制显示时,即使值为0,也依然显示为长度较长 ...

  3. GoCN每日新闻(2019-09-25)

    GoCN每日新闻(2019-09-25) 1. Go module 再回顾 https://colobu.com/2019/09/23/review-go-module-again/2. 如何灵活地进 ...

  4. Go工程项目方面注意

    1.同一个文件夹下的包名必须相同 2.文件夹下go文件使用的包名不是必须同文件夹名,但建议包名同文件夹名 3.不用目录包名不同 4.调用不同包里面的函数格式:包名.函数名(...) 5.包导出给外部使 ...

  5. 实现一个兼容eleUI form表单的多选组件

    本质上是实现了一个eleUI select组件中的创建条目功能的组件,仅仅是将dropdown的选择框变成了label形式.支持eleUI的form表单校验,同时组件也提供了组件内自定义校验的方法.常 ...

  6. VsCode插件与Node.js交互通信

    首先关于VsCode插件通信,如果不明白的可以参考我的这篇博客VsCode插件开发之插件初步通信 如果需要详细例子的话,可以参考VsCode插件开发 现在又有一个新的需求是,VsCode插件可以通过j ...

  7. appium+python 微信小程序的自动化

    sudo kill -9 $(lsof -i:8889 -t) mitmweb -p 8889 -s addons.py mitmdump -q  -p 8889 -s addons.py http: ...

  8. Spark(四十九):Spark On YARN启动流程源码分析(一)

    引导: 该篇章主要讲解执行spark-submit.sh提交到将任务提交给Yarn阶段代码分析. spark-submit的入口函数 一般提交一个spark作业的方式采用spark-submit来提交 ...

  9. GIS自定义地理处理工具--极值提取

    GIS自定义地理处理工具--极值提取 关键词:最大值提取,最小值提取,极值提取,极小值提取,极大值提取 商务合作,科技咨询,版权转让:向日葵,135—4855__4328,xiexiaokui#qq. ...

  10. QEMU命令配置虚拟机网络的用户模式

    QEMU缺省使用“-net nic-net user”参数为客户机配置网络,提供了一种用户模式( user-mode)的网络模拟.使用用户模式的客户机可以连通宿主机及外部网络.用户模式网络完全由QEM ...