[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 ...
随机推荐
- JavaScript关于闭包
在学习JavaScript这条路上,对于闭包这个JS中极其重要的应用技巧或者说是一个语言特性一直停留在最最表层的: 函数α内部的函数β被函数外部所调用,然后内部的函数β因为被调用使得其生存周期得以延长 ...
- JStorm开发经验+运维经验总结
1.开发经验总结 ——12 Sep 2014 · 8 revisions 在jstorm中, spout中nextTuple和ack/fail运行在不同的线程中, 从而鼓励用户在nextTuple里 ...
- 【BZOJ3207】花神的嘲讽计划Ⅰ Hash+主席树
[BZOJ3207]花神的嘲讽计划Ⅰ Description 背景 花神是神,一大癖好就是嘲讽大J,举例如下: “哎你傻不傻的![hqz:大笨J]” “这道题又被J屎过了!!” “J这程序怎么跑这么快 ...
- iOS UITableView划动删除的实现
标签:划动删除 iphone 滑动删除 ios UITableView 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://rainb ...
- ORACLE的测试用户Scott
Oracle数据库的测试用户Scott的密码为什么是Tiger? 1977年6月,Larry Ellison 与 Bob Miner 和 Ed Oates 在硅谷共同创办了一家名为软件开发实验室(So ...
- 每隔10秒钟打印一个“Helloworld”
/** * 每隔10秒钟打印一个“Helloworld” */ public class Test03 { public static void main(String[] args) throws ...
- 字符串 (string)与字节数组(byte[])之间的转换
string str = "abc" //字符串转成编码为GB2312的byte[] byte[] pData =System.Text.Encoding.GetEncoding( ...
- MySQL数据库(4)- 多表查询、可视化工具Navicat的使用、设计模式MVC
一.多表查询 准备工作:创建两张表,部门表(department).员工表(employee),代码和表格如下: # 创建表 create table department( id int, name ...
- 添加git忽略文件
把之前的文件添加作为忽略文件 先把本地缓存删除(改变成未track状态),然后再提交git rm -r --cached .git add .git commit -m 'commit log inf ...
- 【ORACLE】10步全然卸载CRS
版权声明:本文为博主原创文章(原文:blog.csdn.net/clark_xu 徐长亮的专栏),未经博主同意不得转载. https://blog.csdn.net/u011538954/articl ...