HDU 5311 Hidden String (暴力)
题意:今天是BestCoder一周年纪念日. 比赛管理员Soda有一个长度为n的字符串s. 他想要知道能否找到s的三个互不相交的子串s[l1..r1], s[l2..r2], s[l3..r3]满足下列条件:
1. 1≤l1≤r1<l2≤r2<l3≤r3≤n 2. s[l1..r1], s[l2..r2], s[l3..r3]依次连接之后得到字符串"anniversary". 特别注意:式子中红色符号!!! 思路:其实就是要在一个串中找可能存在的3个连续子串来构成这个"anniversary",穷举第一个串的大小,再穷举第2个串的大小,剩下的由第3个串来搞定。每个串必须大于等于1的大小才行,而且不能重叠到。 如果用的是string自带的find,还需要特别注意的是OJ上string::npos可能并不是你机器上定义的那样,可能是-1,可能是unsigned的无穷大!总之最好避开这些东西~ 就是这里wa到怕了,因为BC和HDU上的并不一样,所以我在BC上交就过了,而HDU没过。
BC上交的:
//#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#define LL long long
#define pii pair<int,int>
#define INF 0x7f7f7f7f
using namespace std;
const int N=; string str;
string tmp="anniversary"; int cal(int len)
{
if(len<tmp.size()) return false;//不可能
if(str.find( tmp )!= string::npos) return true;
if(len==tmp.size()) //相同串
{
if(str.find( tmp )!= string::npos) return true;
else return false;
} for(int i=; i<; i++)
{
unsigned int s1=str.find(tmp.substr(, i));
if( s1+tmp.size()>=len || s1==string::npos ) continue; for(int j=; j+i<; j++)
{
unsigned int s2=str.find( tmp.substr(i, j), s1+i );
if( s2==string::npos ) continue;
int k=-j-i;
if( str.find( tmp.substr(i+j, k), s2+j )!=string::npos)
{
return true;
} }
}
return false;
} int main()
{
//freopen("input.txt", "r", stdin);
int n, m, t, p, q; cin>>t;
while(t--)
{
cin>>str;
bool tmp=cal(str.size());
if(tmp) puts("YES");
else puts("NO");
}
return ;
}
AC代码
HDU 上的:
#include <bits/stdc++.h>
#define LL long long
#define pii pair<int,int>
#define INF 0x7f7f7f7f
using namespace std;
const int N=; string str;
string tmp="anniversary";
int cal(int len)
{
for(int i=; i+<=tmp.size(); i++)
{
int s1=str.find(tmp.substr(, i), );
if( s1< ) continue; for(int j=; j+i+<=tmp.size(); j++)
{
int s2=str.find( tmp.substr(i, j), s1+i );
if( s2< ) continue; int k=tmp.size()-j-i;
if(k<) continue;
if( str.find( tmp.substr(i+j, k), s2+j )< )
return true;
}
}
return false;
}
int main()
{
freopen("input.txt", "r", stdin);
int n, m, t, p, q;
cin>>t;
while(t--)
{
cin>>str;
if( cal( str.size() ) ) printf("YES\n");
else printf("NO\n");
}
return ;
}
AC代码
HDU 5311 Hidden String (暴力)的更多相关文章
- hdu 5311 Hidden String
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5311 Hidden String Description Today is the 1st anniv ...
- hdu 5311 Hidden String (BestCoder 1st Anniversary ($))(深搜)
http://acm.hdu.edu.cn/showproblem.php?pid=5311 Hidden String Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 5311 Hidden String (优美的暴力)
Hidden String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) ...
- hdu 5311 Hidden String 字符串
BC一周年的题.这道题做比赛的时候A了小数据,终于评判的时候还是挂了,看来还是不认真思考的问题啊.交的时候 都没有信心过肯定是不行的.认真思考.敲一发,有信心过才是真正的acmer.赛后认真想了想,发 ...
- hdu 5311 Hidden String(find,substr)
Problem Description Today is the 1st anniversary of BestCoder. Soda, the contest manager, gets a str ...
- hdoj 5311 Hidden String(KMP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5311 思路分析:该问题要求在字符串中是否存在三个不相交的子串s[l1..r1], s[l2..r2], ...
- HDU 5311:Hidden String
Hidden String Accepts: 437 Submissions: 2174 Time Limit: 2000/1000 MS (Java/Others) Memory Limit ...
- BestCoder 1st Anniversary ($) 1002.Hidden String
Hidden String Accepts: 437 Submissions: 2174 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 26 ...
- BestCoder 1st Anniversary B.Hidden String DFS
B. Hidden String Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/co ...
随机推荐
- 【HDOJ】【2089】不要62
数位DP cxlove基础数位DP第一题 用容斥把所有的不吉利数字去掉就得到吉利数字的数量= =(满足区间减法) //HDOJ 2089 #include<cmath> #include& ...
- 20160729noip模拟赛zld
首先显然有多少个奇数,就有多少个回文串是最优的(没有奇数时构造一个回文串 然后有了k个“核心”,把剩下的字符顺序安排到这些的两侧,最后最短的回文串长度就是答案 #include<map> ...
- [转载]App.Config详解及读写操作
App.Config详解 应用程序配置文件是标准的 XML 文件,XML 标记和属性是区分大小写的.它是可以按需要更改的,开发人员可以使用配置文件来更改设置,而不必重编译应用程序.配置文件的根节点是c ...
- c++ 虚继承与继承的差异 (转)
转自:CSDN dqjyong 原文链接:http://blog.csdn.net/dqjyong/article/details/8029527 前面一篇文章,说明了在C++ 虚继承对基类构造函数调 ...
- POJ 1979 Red and Black(水题,递归)
一开始理解错题意了,以为是走过的砖不能再重复走,最多能走多少个黑砖,结果写的递归陷入死循环...后来才明白原来可以重复走,问可以到达的磁砖数. #include <iostream> #i ...
- Ubuntu环境下Hadoop1.2.1, HBase0.94.25, nutch2.2.1各个配置文件一览
/×××××××××××××××××××××××××××××××××××××××××/ Author:xxx0624 HomePage:http://www.cnblogs.com/xxx0624/ ...
- ibatis动态查询
在复杂查询过程中,我们常常需要根据用户的选择决定查询条件,这里发生变化的并不只是SQL 中的参数,包括Select 语句中所包括的字段和限定条件,都可能发生变化.典型情况,如在一个复杂的组合查询页面, ...
- ibatis框架文件配置
最近2天在学ibatis,心里也有一些心得,就把它写下来了. 首先是配置一下ibatis的环境,添加ibatis2.X.jar,mysql-connection-bin.5.1.8.jar,建立一个w ...
- Windows下gcc以及Qt的DLL文件调用之总结(三种方法)
DLL与LIB的区别 :1.DLL是一个完整程序,其已经经过链接,即不存在同名引用,且有导出表,与导入表lib是一个代码集(也叫函数集)他没有链接,所以lib有冗余,当两个lib相链接时地址会重新建立 ...
- linux 免交互状态下修改用户密码
当利用某些工具对linux用户进行远程密码更改时,输入[ passwd 用户名 ] 后需要输入两次密码, 但是如果你利用的某些工具无法与linux进行交互的情况下,就没办法变更用户密码了,这个时候可以 ...