码迷,mamicode.com
首页 > 其他好文 > 详细

F. Fixing Banners

时间:2019-11-04 00:12:49      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:namespace   grant   rom   however   original   event   ring   position   cli   

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 (1T50000)

, 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 2106

.

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[8][2000010];
int vis[8][8];
int v[8];
int flag ;



void dfs(int num)
{
    if(flag) return ;
    if(num >= 7)
    {
        flag = 1 ;
        return ;
    }
    for(int i = 1 ; i <= 6 ; i++)
    {
        if(!v[i] && vis[i][num])
        {
            v[i] = 1 ;
            dfs(num+1);
            v[i] = 0 ;
        }
    }
}

int main()
{
    int t;
    scanf("%d" , &t);
    int p = t ;
    while(t--)
    {
        if(p == t + 1)
            getchar();
        memset(vis , 0  , sizeof(vis));
        memset(v , 0 , sizeof(v));
        for(int i = 1 ; i <= 6 ; i++)
        {
            char c ;
            while(c = getchar())
            {
                if(c == \n) break ;
                else if(c == h)
                    vis[i][1] = 1 ;
                else if(c == a)
                    vis[i][2] = 1 ;
                else if(c == r)
                    vis[i][3] = 1 ;
                else if(c == b)
                    vis[i][4] = 1 ;
                else if(c == i)
                    vis[i][5] = 1 ;
                else if(c == n)
                    vis[i][6] = 1 ;
            }
        }
        flag = 0;
        dfs(1);
        if(flag)
            cout << "Yes" << endl ;
        else
            cout << "No" << endl ;
    }


    return 0 ;
}

 

F. Fixing Banners

标签:namespace   grant   rom   however   original   event   ring   position   cli   

原文地址:https://www.cnblogs.com/nonames/p/11789776.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!