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 ...
随机推荐
- UVA 714 Copying Books 二分
题目链接: 题目 Copying Books Time limit: 3.000 seconds 问题描述 Before the invention of book-printing, it was ...
- Unity3D IOS IPhone添加Admob的方法
原地址:http://dong2008hong.blog.163.com/blog/static/4696882720140403119293/ 首先阅读官方文档https://developers. ...
- orale内置函数COALESCE和GREATEST和LEAST
1. COALESCE 返回该表达式列表的第一个非空value. 格式: COALESCE(value1, value2, value3, ...) 含义: 返回value列表第一个非空的值. val ...
- Android 解决ListView中每一项与button冲突
在listView的item里面如果有button,ImageButton等控件,会使得ListView不会被点击,解决方法是: ①在Button上面添加属性 android:focusable=&q ...
- SpringMVC学习总结(二)——DispatcherServlet详解
摘要: DispatcherServlet是前端控制器设计模式的实现,提供Spring Web MVC的集中访问点,而且负责职责的分派,而且与Spring IoC容器无缝集成,从而可以获得Spring ...
- Visual StudioTools for Unity 使用技巧2
在之前的博客介绍了 Visual Studio Tools for Unity的安装和使用. http://www.cnblogs.com/petto/p/3886811.html 其实这个工具还提供 ...
- vc2005中没有classwizard这个命令
vc2005中没有classwizard这个命令了 2005下怎么添加鼠标事件 vc2005中没有classwizard这个命令了 取代classwizard 中的添加消息映射,添加类,等等的功能主要 ...
- phantomjs使用说明
phantomjs使用说明 12条评论 phantomjs实现了一个无界面的webkit浏览器.虽然没有界面,但dom渲染.js运行.网络访问.canvas/svg绘制等功能都很完备,在页面抓取. ...
- Junit使用教程(四)
一.会用Spring测试套件的好处 在开发基于Spring的应用时,如果你还直接使用Junit进行单元测试,那你就错过了Spring为我们所提供的饕餮大餐了.使用Junit直接进行单元测试有以下四大不 ...
- 开发板挂载nfs服务器错误解析
输入mount -t nfs 192.168.1.110:/home/work /mnt,这时可能会出现 mount.nfs:access denied by server while mountin ...