http://codeforces.com/gym/102394/problem/F

F. Fixing Banners
time limit per test

1 second

memory limit per test

512 megabytes

input

standard input

output

standard output

Harbin, whose name was originally a Manchu word meaning "a place for drying fishing nets", grew from a small rural settlement on the Songhua River to become one of the largest cities in Northeast China. Founded in 1898 with the coming of the Chinese Eastern Railway, the city first prospered as a region inhabited by an overwhelming majority of the immigrants from the Russian Empire. Now, Harbin is the capital of Heilongjiang province and the largest city in the northeastern region of the People's Republic of China. It serves as a key political, economic, scientific, cultural, and communications hub in Northeast China, as well as an important industrial base of the nation.

This year, a CCPC regional contest is going to be held in this wonderful city, hosted by Northeast Forestry University. To ensure the contest will be a success and enjoyed by programmers around the country, preparations for the event are well underway months before the contest.

You are the leader of a student volunteer group in charge of making banners to decorate the campus during the event. Unfortunately, your group made a mistake and misprinted one of the banners. To be precise, the word "harbin" is missing in that banner. Because you don't have time to reprint it, the only way to fix it is to cut letters from some used old banners and paste them onto the misprinted banner. You have exactly six banners, and for some reason, you must cut exactly one letter from each banner. Then, you can arrange and paste the six letters onto the misprinted banner and try to make the missing word "harbin". However, before you start cutting, you decide to write a program to see if this is possible at all.

Input

The input contains multiple cases. The first line of the input contains a single integer T (1≤T≤50000)

, the number of cases.

For each case, the input contains six lines. Each line contains a non-empty string consisting only of lowercase English letters, describing the letters on one of the old banners.

The total length of all strings in all cases doesn't exceed 2⋅106

.

Output

For each case, print the string "Yes" (without quotes) if it is possible to make the word "harbin", otherwise print the string "No" (without quotes).

Example
Input

Copy
2
welcome
toparticipate
inthe
ccpccontest
inharbin
inoctober
harvest
belong
ninja
reset
amazing
intriguing
Output

Copy
No
Yes
题意:从六个字符串中分别找出一个字符,问能否组成“harbin“字符串。
解法:dfs搜索;
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <stdio.h>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string.h>
#include <vector>
#define ME(x , y) memset(x , y , sizeof(x))
#define SF(n) scanf("%d" , &n)
#define rep(i , n) for(int i = 0 ; i < n ; i ++)
#define INF 0x3f3f3f3f
#define mod 998244353
#define PI acos(-1)
using namespace std;
typedef long long ll ;
char s[][];
int vis[][];
int v[];
int flag ; void dfs(int num)
{
if(flag) return ;
if(num >= )
{
flag = ;
return ;
}
for(int i = ; i <= ; i++)
{
if(!v[i] && vis[i][num])
{
v[i] = ;
dfs(num+);
v[i] = ;
}
}
} int main()
{
int t;
scanf("%d" , &t);
int p = t ;
while(t--)
{
if(p == t + )
getchar();
memset(vis , , sizeof(vis));
memset(v , , sizeof(v));
for(int i = ; i <= ; i++)
{
char c ;
while(c = getchar())
{
if(c == '\n') break ;
else if(c == 'h')
vis[i][] = ;
else if(c == 'a')
vis[i][] = ;
else if(c == 'r')
vis[i][] = ;
else if(c == 'b')
vis[i][] = ;
else if(c == 'i')
vis[i][] = ;
else if(c == 'n')
vis[i][] = ;
}
}
flag = ;
dfs();
if(flag)
cout << "Yes" << endl ;
else
cout << "No" << endl ;
} return ;
}

F. Fixing Banners的更多相关文章

  1. The 2019 China Collegiate Pro gramming Contest Harbin Site (F. Fixing Banners)

    F. Fixing Banners time limit per test 1 second memory limit per test 512 megabytes input standard in ...

  2. The 2019 China Collegiate Programming Contest Harbin Site F. Fixing Banners

    链接: https://codeforces.com/gym/102394/problem/F 题意: Harbin, whose name was originally a Manchu word ...

  3. The 2019 China Collegiate Programming Contest Harbin Site

    题解: https://files.cnblogs.com/files/clrs97/HarbinEditorialV2.zip Code: A. Artful Paintings /* let x= ...

  4. 模拟赛小结:The 2019 China Collegiate Programming Contest Harbin Site

    比赛链接:传送门 上半场5题,下半场疯狂挂机,然后又是差一题金,万年银首也太难受了. (每次银首都会想起前队友的灵魂拷问:你们队练习的时候进金区的次数多不多啊?) Problem J. Justify ...

  5. Mysql_以案例为基准之查询

    查询数据操作

  6. F. Igor and Interesting Numbers

    http://codeforces.com/contest/747/problem/F cf #387 div2 problem f 非常好的一道题.看完题,然后就不知道怎么做,感觉是dp,但是不知道 ...

  7. 在 C# 里使用 F# 的 option 变量

    在使用 C# 与 F# 混合编程的时候(通常是使用 C# 实现 GUI,F#负责数据处理),经常会遇到要判断一个 option 是 None 还是 Some.虽然 Option module 里有 i ...

  8. 如果你也会C#,那不妨了解下F#(7):面向对象编程之继承、接口和泛型

    前言 面向对象三大基本特性:封装.继承.多态.上一篇中介绍了类的定义,下面就了解下F#中继承和多态的使用吧.

  9. 如果你也会C#,那不妨了解下F#(2):数值运算和流程控制语法

    本文链接:http://www.cnblogs.com/hjklin/p/fs-for-cs-dev-2.html 一些废话 一门语言火不火,与语言本身并没太大关系,主要看语言的推广. 推广得好,用的 ...

随机推荐

  1. 基于VUE多人聊天项目

    项目背景 公司平台要做一个通讯系统,本来是java 来做的后面改前端+PHP来做,所以就用VUE来做这个了. github github地址 新人求star 技术栈 vue-axios vuex we ...

  2. 关于反射和动态代理和AOP

    package Exercise.reflect; /** * 反射把java中所有的东西都当做对象,甚至是类的本身也作为一种对象,并把它作为Class的对象的实例: * 反射是把类.类的属性.方法都 ...

  3. IDEA maven 配置,运行比较慢,加截本地仓库资源数据

    在 Runner 配置了参数: -DarchetypeCatalog=internal

  4. MCU2FPGA之SPI时序总线

    转载自:http://blog.csdn.net/ce123/article/details/6895408 SPI总线有四种工作方式(SP0, SP1, SP2, SP3),其中使用的最为广泛的是S ...

  5. Spring read-only="true" 只读事务的一些概念

    概念:从这一点设置的时间点开始(时间点a)到这个事务结束的过程中,其他事务所提交的数据,该事务将看不见!(查询中不会出现别人在时间点a之后提交的数据) 应用场合: 如果你一次执行单条查询语句,则没有必 ...

  6. luogu 5471 [NOI2019]弹跳 KDtree + Dijkstra

    题目链接 第一眼就是 $KDtree$ 优化建图然而,空间只有 $128mb$,开不下   时间不吃紧,考虑直接跑 $Dijkstra$ $Dijkstra$ 中存储的是起点到每个输入时给出的矩阵的最 ...

  7. 小程序封装wx.request,以及调用

    1.新建一个api目录,与pages同级 2.在api目录下新建一个api.js文件 3.编写代码 const host = 'http://test.test.cn' const wxRequest ...

  8. es之Source字段和store字段

    PUT /website/blog/ { "title" : "elasticsearchshi是是什么", "author" : &quo ...

  9. android中各种组件的生命周期问题

    1,activiy生命周期 http://www.ibm.com/developerworks/cn/opensource/os-cn-android-actvt/ 结合ativity的状态转换来看才 ...

  10. 阿里云配置通用服务的坑 ssh: connect to host 47.103.101.102 port 22: Connection refused

    1.~ wjw$ ssh root@47.103.101.102 ssh: connect to host 47.103.101.102 port 22: Connection refused ssh ...