[Usaco2008 Open]Word Power 名字的能量
1622: [Usaco2008 Open]Word Power 名字的能量
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 408 Solved: 198
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
Bessie
Jonathan
Montgomery
Alicia
Angola
se
nGo
Ont
INPUT DETAILS:
There are 5 cows, and their names are "Bessie", "Jonathan",
"Montgomery", "Alicia", and "Angola". The 3 good strings are "se",
"nGo", and "Ont".
Sample Output
1
2
0
1
OUTPUT DETAILS:
"Bessie" contains "se", "Jonathan" contains "Ont", "Montgomery" contains
both "nGo" and "Ont", Alicia contains none of the good strings, and
"Angola" contains "nGo".
HINT
Source
本来想找一道字符串的题,看着像是一道模拟,直接爆搜,但是超时了好几次。。。下面是两种写法,一个是6100多毫秒个计时器掐了,另一种却是200多毫秒AC。。。。
先来个超时的。。。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<bits/stdc++.h>
using namespace std;
int N,M;
char T[][];
char P[][];
int lenT[];
int lenP[];
int main(){ cin>>N>>M;
for(int i=;i<=N;i++) scanf("%s",T[i]);
for(int i=;i<=M;i++) scanf("%s",P[i]); for(int i=;i<=N;i++){
for(int j=;j<=strlen(T[i])-;j++){
if(int(T[i][j])>=)
T[i][j]=char(int(T[i][j])-);
}
} for(int i=;i<=M;i++){
for(int j=;j<=strlen(P[i])-;j++){
if(int(P[i][j])>=)
P[i][j]=char(int(P[i][j])-);
}
} for(int i=;i<=N;i++){
int ANS=;
for(int j=;j<=M;j++){
int now=;
int len=strlen(P[j]);
for(int k=;k<=strlen(T[i])-;k++){
if(T[i][k]==P[j][now]){
now++;
if(now==len){
ANS++;
break;
}
}
} }
cout<<ANS<<endl;
} return ;
}
然后改成这个就AC了,至少快了30多倍。。。差别很大么?
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<bits/stdc++.h>
using namespace std;
int N,M;
char T[][];
char P[][];
int lenT[];
int lenP[];
int main(){ cin>>N>>M; for (int i=;i<=N;i++){
scanf("%s",T[i]);
while (T[i][lenT[i]])
{
if (int(T[i][lenT[i]])<)
T[i][lenT[i]]=char(int(T[i][lenT[i]])+);
lenT[i]++;
}
} for (int i=;i<=M;i++){
scanf("%s",P[i]);
while(P[i][lenP[i]])
{
if(int(P[i][lenP[i]])<)
P[i][lenP[i]]=char(int(P[i][lenP[i]])+);
lenP[i]++;
}
} for(int i=;i<=N;i++){
int ANS=;
for(int j=;j<=M;j++){
int now=;
for(int k=;k<=lenT[i]-;k++){
if(T[i][k]==P[j][now]){
now++;
if(now==lenP[j]){
ANS++;
break;
}
}
} }
cout<<ANS<<endl;
} return ;
}
[Usaco2008 Open]Word Power 名字的能量的更多相关文章
- BZOJ 1622: [Usaco2008 Open]Word Power 名字的能量
题目 1622: [Usaco2008 Open]Word Power 名字的能量 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 349 Solved ...
- 1622: [Usaco2008 Open]Word Power 名字的能量
1622: [Usaco2008 Open]Word Power 名字的能量 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 370 Solved: 18 ...
- bzoj1622 [Usaco2008 Open]Word Power 名字的能量
Description 约翰想要计算他那N(1≤N≤1000)只奶牛的名字的能量.每只奶牛的名字由不超过1000个字待构成,没有一个名字是空字体串, 约翰有一张“能量字符串表”,上面有M(1 ...
- 【BZOJ】1622: [Usaco2008 Open]Word Power 名字的能量(dp/-模拟)
http://www.lydsy.com/JudgeOnline/problem.php?id=1622 这题我搜的题解是dp,我也觉得是dp,但是好像比模拟慢啊!!!! 1400ms不科学! 设f[ ...
- BZOJ——1622: [Usaco2008 Open]Word Power 名字的能量
http://www.lydsy.com/JudgeOnline/problem.php?id=1622 Description 约翰想要计算他那N(1≤N≤1000)只奶牛的名字的能量.每只 ...
- bzoj 1622: [Usaco2008 Open]Word Power 名字的能量【模拟】
模拟即可,注意包含可以是不连续的 方便起见读入的时候全转成小写 #include<iostream> #include<cstdio> using namespace std; ...
- BZOJ_1622_[Usaco2008_Open]_Word_Power_名字的能量_(字符匹配_暴力)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1622 给出多个文本串和模式串,求每个文本串中有多少模式串. 分析 直接暴力... #inclu ...
- 洛谷——P2908 [USACO08OPEN]文字的力量Word Power
P2908 [USACO08OPEN]文字的力量Word Power 题目描述 Farmer John wants to evaluate the quality of the names of hi ...
- 洛谷 P2908 [USACO08OPEN]文字的力量Word Power
P2908 [USACO08OPEN]文字的力量Word Power 题目描述 Farmer John wants to evaluate the quality of the names of hi ...
随机推荐
- django数据库读写分离,分库
读写分离 在settings中配置不同名称的数据库连接参数,并配置一条数据库选择路由 DATABASES = { 'default': { 'ENGINE': 'django.db.backends. ...
- 你一定喜欢看的 Webpack 2.× 入门实战
from:https://www.jianshu.com/p/b83a251d53db?utm_campaign=maleskine&utm_content=note&utm_medi ...
- openvswitch总述
前面用了两天时间了解了OpenvSwitch的结构,今天参考其他资料加自己的心得做个总结 一. openvswitch的安装和使用 在前一篇文章中详细的介绍了OpenvSwitch的安装和使用,不再赘 ...
- 【BZOJ4567】[Scoi2016]背单词 Trie树+贪心
[BZOJ4567][Scoi2016]背单词 Description Lweb 面对如山的英语单词,陷入了深深的沉思,“我怎么样才能快点学完,然后去玩三国杀呢?”.这时候睿智 的凤老师从远处飘来,他 ...
- iOS 7.1 UITapGestureRecognizer 不好用的解决办法
UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(o ...
- linux运维 vi vim q 的间接注释
w q --不发生写的写,无增删效果. 点q后,再次执行 vi /var/www/share/w.php 仍然会‘ Found a swap file by the name "/var/ ...
- php5.4 的 php-fpm 的重启
php 5.3.3以后 源码中已经内嵌了 php-fpm,不用象以前的php版本一样专门打补丁了,只需要在configure的时候添加编译参数即可. 关于php-fpm的编译参数有 –enable-f ...
- SEO优化 给a标签添加rel="nofollow"
为什么要使用nofollow标签? 我们使用nofollow标签的目的是很明确的,就是减少蜘蛛对页面上垃圾链接的爬行和传递权重,或者减少蜘蛛对页面上“无用”链接的爬行和传递链接权重. 这里所说的无用是 ...
- 洛谷P4475 巧克力王国
洛谷P4475 巧克力王国 题目描述 巧克力王国里的巧克力都是由牛奶和可可做成的. 但是并不是每一块巧克力都受王国人民的欢迎,因为大家都不喜欢过于甜的巧克力. 对于每一块巧克力,我们设 x 和 y 为 ...
- 前端基础-css(1)
一.css的引入方式 现在的互联网前端分三层: HTML:超文本标记语言.从语义的角度描述页面结构. CSS:层叠样式表.从审美的角度负责页面样式. JS:JavaScript .从交互的角度描述页面 ...