HDU 5284 wyh2000 and a string problem(字符串,水)
题意:比如给你一个串,要求判断wyh是不是它的子序列,那么你只需要找一个w,找一个y,再找一个h,使得w在y前面,y在h前面即可。有一天小学生拿着一个串问他“wyh是不是这个串的子序列?”.但是wyh2000有重度近视眼,如果字符串中有一段连续的v(至少两个),那么他会把它看成一个w。例如,字符串vvv会被看成w,字符串vvwvvv会被看成www,字符串vwvv会被看成vww。请问wyh2000会怎么回答这个问题?输出yes和no。
思路:其实就是将两个以上的v换成w,再来看是否能有'wyh'子串的存在。可以写更技巧些,但是为了快,就随便写了。还好过了。
//#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <iostream>
#define LL long long
#define pii pair<int,int>
#define INF 0x7f7f7f7f
using namespace std;
const int N=; char s[N];
char ans[N]; int main()
{
//freopen("input.txt", "r", stdin);
int t;
cin>>t;
while(t--)
{
scanf("%s",s);
int len=strlen(s);
int p=;
ans[++p]=s[];
for(int i=; i<len; i++)//替换掉
{
if(ans[p]=='v'&&s[i]=='v')
{
ans[p]='w';
while(s[i]=='v') i++;
i--;
}
else ans[++p]=s[i];
}
ans[++p]='\0';
len=p; int i=;
bool w=false, y=false, h=false;
while(i<len&&ans[i]!='w') i++;//找3个字符出来
if(i<len&&ans[i]=='w') w=; while(i<len&&ans[i]!='y') i++;
if(i<len&&ans[i]=='y') y=; while(i<len&&ans[i]!='h') i++;
if(i<len&&ans[i]=='h') h=;
if(w&&y&&h) puts("Yes");
else puts("No");
}
return ;
}
AC代码
HDU 5284 wyh2000 and a string problem(字符串,水)的更多相关文章
- hdu 5284 wyh2000 and a string problem(没有算法,仅仅考思维,字符数组得开20万,不然太小了)
代码: #include<cstdio> #include<cstring> using namespace std; char s[200000]; int main() { ...
- bestcoder 48# wyh2000 and a string problem (水题)
wyh2000 and a string problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K ...
- hdu 3374 String Problem (字符串最小最大表示 + KMP求循环节)
Problem - 3374 KMP求循环节. http://www.cnblogs.com/wuyiqi/archive/2012/01/06/2314078.html 循环节推导的证明相当 ...
- HDU 3374 String Problem (KMP+最大最小表示)
HDU 3374 String Problem (KMP+最大最小表示) String Problem Time Limit: 2000/1000 MS (Java/Others) Memory ...
- hdu 5772 String problem 最大权闭合子图
String problem 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5772 Description This is a simple pro ...
- hdu String Problem(最小表示法入门题)
hdu 3374 String Problem 最小表示法 view code#include <iostream> #include <cstdio> #include &l ...
- HDU 3374 String Problem(KMP+最大/最小表示)
String Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- String Problem hdu 3374 最小表示法加KMP的next数组
String Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- ACM: HDU 5285 wyh2000 and pupil-二分图判定
HDU 5285 wyh2000 and pupil Time Limit:1500MS Memory Limit:65536KB 64bit IO Format:%I64d &a ...
随机推荐
- qsort/bsearch的应用
问题描述: Description You have just moved from Waterloo to a big city. The people here speak an incompre ...
- 使用文本文件(.txt)进行数据存取的技巧总结(相当的经典)
使用文本文件(.txt)进行数据存取的技巧总结(相当的经典) 使用文本文件(.txt)进行数据存取的技巧总结 由于本帖内容较多,部分转自他人的心得,因此,凡转贴的地方仅用“----转----”标注,原 ...
- Codeforces 402A 402B 402C 402D
402A 直接暴力 #include <cstdio> #include <cstdlib> #include <cmath> #include <map&g ...
- POJ 1716
#include <iostream> #include <algorithm> #define MAXN 20005 using namespace std; int _m[ ...
- Java Socket编程readLine返回null,read返回-1的条件
客户端正常关闭socket的时候,服务器端的readLine()方法会返回null,或者read()方法会返回-1
- CF 221div2 A. Lever
A. Lever 题目:http://codeforces.com/contest/376/problem/A 题意:杠杆原理 比两边的重量 input =^== output balance 9== ...
- Enum枚举 简单的使用
在枚举中使用抽象方法 /** * 为枚举类定义一个抽象方法,<br/> * 这个抽象方法由不同的枚举值提供不同的实现 * * @author wangzhu * @date 2014-9- ...
- Java学习笔记(二)UML基础
用例图:代表系统的一个功能模块,仅仅是系统功能的描述.用例图包括:用例.角色.角色和用例之间的关系以及系统内用例之间的关系. 类图:表示系统中包含哪些实体,各实体之间如何关联. 类图除了表示实体内部结 ...
- 大陆 Google play 开发者注册(2016)
1:准备一个VPN, 如: https://vpnso.com 收费的,使用一两年了,还不错,很稳定2:准备一张普通的银行卡或者信用卡就可以了,能正常绑定支付宝就行3:在全球付上面申请一个 虚拟 ...
- Linux之SAMBA共享服务
简述 Samba服务器可以让Windows操作系统用户访问局域网中Linux主机,就象访问网上邻居一样方便. 具有以下功能: 共享目录:在局域网上共享某个或某些目录,使得同一个网络内的Windows用 ...