【比赛链接】click here~~
【题目】
1001 wyh2000 and a string problem
青年理论计算机科学家wyh2000在教小学生一些基础的字符串概念。 定义一个字符串s 的子序列为将s 中一些元素删掉得到的字符串。可以删掉全部元素,可以不删,也可以只删一些。 他还教了小学生如何判断一个串是不是另一个串的子序列。比如给你一个串,要求判断wyh 是不是它的子序列,那么你只需要找一个w ,找一个y ,再找一个h ,使得w 在y 前面,y 在h 前面即可。 有一天小学生拿着一个串问他“wyh 是不是这个串的子序列?” 但是wyh2000有重度近视眼,如果字符串中有一段连续的v (至少两个),那么他会把它看成一个w 。例如,字符串vvv 会被看成w ,字符串vvwvvv 会被看成www ,字符串vwvv 会被看成vww 。 请问wyh2000会怎么回答这个问题?
第一行为数据组数T(1≤T≤105) 。 接下来T 行,每行一个字符串,表示小学生拿来问wyh2000的串。 总串长不超过3145728。只包含小写字母。 hack数据字符串长度不超过100000。
对于每组数据,如果wyh2000会把wyh 看成该串的子串,那么输出一行Yes ,否则输出一行No 。
4 woshiyangli woyeshiyangli vvuuyeh vuvuyeh
No Yes Yes No【代码】:
// C
/*--------------简单字符串处理-----------*/
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define rep(i,j,k) for(int i=(int)j;i<(int)k;++i)
#define per(i,j,k) for(int i=(int)j;i>(int)k;--i)
#define lowbit(a) a&-a
#define Max(a,b) a>b?a:b
#define Min(a,b) a>b?b:a
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long LL;
typedef unsigned long long LLU;
typedef double db;
const int N=2*1e5+100;
const int inf=0x3f3f3f3f;
int n,m,t,ans,res,cnt,tmp;
int a[N],b[N],c[N];
char str[N];
bool vis[N];
int dir4[4][2]= {{1,0},{0,1},{-1,0},{0,-1}};
int dir8[8][2]= {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
int movv[5][2]= {{1,0},{0,1},{0,0},{-1,0},{0,-1}};
inline LL read()
{
int c=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
c=c*10+ch-'0';
ch=getchar();
}
return c*f;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%s",str);
int len=strlen(str);
int ff=0;
for(int i=0; i<len; i++)
{
if(ff==0)
{
if(str[i]=='w'||str[i]=='v'&&str[i+1]=='v')
ff=1;
}
if(ff==1)
{
if(str[i]=='y')
ff=2;
}
if(ff==2)
{
if(str[i]=='h')
ff=3;
}
}
if(ff==3) puts("Yes");
else puts("No");
}
return 0;
}
/*
Sample Input
4
woshiyangli
woyeshiyangli
vvuuyeh
vuvuyeh
Sample Output
No
Yes
Yes
No
*/
青年理论计算机科学家wyh2000在教导他的小学生。 共有n 个小学生,编号为1?n 。为了增加小学生之间的凝聚力,wyh2000决定将所有小学生分成2 组,每组都至少有1 个人。 但是有些小学生之间并不认识,而且如果a 不认识b ,那么b 也不认识a 。 Wyh2000希望每组中的小学生都互相认识。而且第一组的人要尽可能多。 请你帮wyh2000求出第一组和第二组的人数是多少。如果找不到分组方案,则输出"Poor wyh"。
第一行一个数T ,表示数据组数。 对于每组数据,第一行两个数n,m ,表示小学生数量和互相不认识的小学生的数量。 接下来m 行,每行两个数x,y(x<y) ,表示x 不认识y ,y 不认识x 。保证一对(x,y) 只会出现一次。T≤10,0≤n,m≤100000
对于每组数据,输出答案。
2 8 5 3 4 5 6 1 2 5 8 3 5 5 4 2 3 4 5 3 4 2 4
5 3 Poor wyh【代码】:
PS:注意此题 n<2&&m==0的情况,当时没注意这点,刚做完就被别人用1 1 0 这组数据无情hack 掉!泪已崩~~
// C
/*------------二分图染色+dfs-----------------*/
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define rep(i,j,k) for(int i=(int)j;i<(int)k;++i)
#define per(i,j,k) for(int i=(int)j;i>(int)k;--i)
#define lowbit(a) a&-a
#define Max(a,b) a>b?a:b
#define Min(a,b) a>b?b:a
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long LL;
typedef unsigned long long LLU;
typedef double db;
const int N=1e5+100;
const int inf=0x3f3f3f3f;
char str[N];
int dir4[4][2]= {{1,0},{0,1},{-1,0},{0,-1}};
int dir8[8][2]= {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
int movv[5][2]= {{1,0},{0,1},{0,0},{-1,0},{0,-1}};
int head[N];
int vall[N],okk[10];
int idd;
inline LL read()
{
int c=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
c=c*10+ch-'0';
ch=getchar();
}
return c*f;
}
vector<int> G[N];
int vis[N];
int one,two;
int maxx,minn;
bool dfs(int u,int t)///当前结点,当前节点要染的颜色
{
if(vis[u]){
if(vis[u]==t) return true;
return false;
}
if(t==1) one++;
else two++;
vis[u]=t;
for(int i=0; i< G[u].size(); ++i){
int v = G[u][i];
if(!dfs(v,-t)) return false;
}
return true;
}
int main()
{
int T,u,v,n,m;
T=read();
while(T--){
n=read();
m=read();
for(int i=0; i<=n; ++i) G[i].clear();
while(m--){
u=read(),v=read();
G[u].push_back(v);
G[v].push_back(u);
}
if(n<2){
puts("Poor wyh");
continue;
}
mem(vis,0);
bool flag=true;
one=two=maxx=minn=0;
for(int i=1; i<=n; ++i){
if(!vis[i]){
maxx+=max(one,two);
minn+=min(one,two);
one=two=0;
if(!dfs(i,1))
{
flag=false;
break;
}
}
}
maxx+=max(one,two);
minn+=min(one,two);
if(flag){
if(minn==0) minn++,maxx--;
printf("%d %d\n",maxx,minn);
}
else puts("Poor wyh");
}
return 0;
}
/*
Sample Input
2
8 5
3 4
5 6
1 2
5 8
3 5
5 4
2 3
4 5
3 4
2 4
Sample Output
5 3
Poor wyh
*/
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/u013050857/article/details/46952837