[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 ...
随机推荐
- linux软件的安装和卸载
http://blog.chinaunix.net/uid-25572546-id-1995028.html
- Python_selenium之处理Alert窗
Python_selenium之处理Alert窗 一.介绍 1. 介绍如何通过switch_to方法处理网页Alert窗口 2. 然后我们自己创建一个alert弹窗进行操作 二.测试脚本 1. 测试脚 ...
- AWS系列-磁盘扩容
1 磁盘扩容 1.1 卷介绍 aws磁盘扩容有两个方式 1.购买新的磁盘,挂载到相应的目录 2.原来磁盘做快照,购买新的磁盘,选择恢复快照到硬盘上,这样相当于,从一块硬盘上50G升级到100G 说到a ...
- AVA 8 :从永久区(PermGen)到元空间(Metaspace)
你注意到了吗?JDK 8早期可访问版本已经提供下载了,java 开发人员可以使用java 8 提供的新的语言和运行特性来做一些实验.其中一个特性就是完全的移除永久代(Permanent Generat ...
- CSS-微信开放UI样式
下面的链接是微信开放的CSS的样式: http://weui.github.io/weui/ 附上GitHub地址:https://github.com/weui/weui
- QQ能上,网页打不开
这是一个老问题了,在大学的时候就经常碰到有人问这样的问题,今天写出来祭奠一下,姑凉长点心吧~! 安阳地区DNS:网通202.102.224.68 如果你是电信:222.88.88.88或者直接弄成顶级 ...
- String 转 List<Map<String, Object>>
public static List<Map<String, Object>> toListMap(String json){ List<Object> list ...
- 『浅入深出』MySQL 中事务的实现
在关系型数据库中,事务的重要性不言而喻,只要对数据库稍有了解的人都知道事务具有 ACID 四个基本属性,而我们不知道的可能就是数据库是如何实现这四个属性的:在这篇文章中,我们将对事务的实现进行分析,尝 ...
- pt-online-schema-change 和 oak-online-alter-table功能对比
今天再查看文档的时候突然看到了oak-online-alter-table执行在线ddl,以前只使用过pt-online-schema.所以这里收集一些资料对比下差异,方便日后自己查阅. 一.oak- ...
- 支付宝SDK的使用方法
前奏 现在随着移动开发的快速发展,越来越多的应用要求在线支付功能.最近做了一个关于支付宝支付功能的应用,在使用支付宝的过程中,遇到一些不必要的弯路,因此,写了这篇文章总结一下关于ios开发如何使用支付 ...