[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 ...
随机推荐
- Jquery实现Bootstrap树形列表
http://bookshadow.com/weblog/2014/05/17/jquery-bootstrap-tree-list/
- 自己搭建IntelliJ IDEA授权服务器
https://github.com/Jrohy/Idea_LicenseServer_onekey 运行 bash <(curl -L -s https://raw.githubusercon ...
- 【BZOJ4621】Tc605 DP
[BZOJ4621]Tc605 Description 最初你有一个长度为 N 的数字序列 A.为了方便起见,序列 A 是一个排列. 你可以操作最多 K 次.每一次操作你可以先选定一个 A 的一个子串 ...
- iOS 百度地图获取当前地理位置
// // ViewController.m // BaiDuDemo // // Created by Chocolate. on 15-3-2. // Copyright (c) 2015年 re ...
- mac下面安装多个JDK
JDK8 GA之后,小伙伴们喜大普奔,纷纷跃跃欲试,想体验一下Java8的Lambda等新特性,可是目前Java企业级应用的主打版本还是JDK6, JDK7.因此,我需要在我的电脑上同时有JDK8,J ...
- express, mocha, supertest,istanbul
引子 有群友问到Express怎么做 单元测试/覆盖率测试,这是上篇所遗漏的,特此补上 Express Web测试 做 Express Web 测试首先要面对的问题是在哪端进行测试: 客户端的请求响应 ...
- img标签使用onload进行src更改时出现的内存溢出问题
最近在开发时需要在img标签加载完成后修改src属性,使用了onload方法. 但是在方法体中最后没有把onload事件指向null, 导致了循环调用onload方法,CPU占用一直居高不下,最后只要 ...
- 一.MySQL入门基础
1.关于cmd界面无法启动mysql: 1)必须要使用管理员身份运行cmd程序 2)如果下载MySQL5.7版本的,在windows服务上Mysql的名字默认是MySQL57,因此在cmd运行 net ...
- Keras网络层之“关于Keras的层(Layer)”
关于Keras的“层”(Layer) 所有的Keras层对象都有如下方法: layer.get_weights():返回层的权重(numpy array) layer.set_weights(weig ...
- Java并发—同步容器和并发容器
简述同步容器与并发容器 在Java并发编程中,经常听到同步容器.并发容器之说,那什么是同步容器与并发容器呢?同步容器可以简单地理解为通过synchronized来实现同步的容器,比如Vector.Ha ...