zoukankan      html  css  js  c++  java
  • 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)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 21062⋅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

    题意:有t个测试样例,每个样例6个字符串,问从每个字符串中去一个字符,能否拼成“harbin"

    题解:用DFS对给定的每一个字符串进行搜索,直到凑成六个字符标记结束

    #include<iostream>
    #include<string.h>
    #include<math.h>
    #include<vector>
    using namespace std;
    int v[6][6];
    int vis[6]; 
    int cnt,flag;
    void dfs(int n)
    {
        if(cnt==6)
            flag=1;
        if(flag==1)
            return ;
        if(flag==0)
            return ;
        else
        {
            int fla=0;
            for(int i=0;i<6;i++)
            {
                if(v[n][i]&&vis[i]==0)
                {
                    vis[i]=1;
                    cnt++;
                    dfs(n+1);
                    vis[i]=0;
                    cnt--;
                }
                if(v[n][i])
                    fla=1;
            }
            if(fla==0)
               flag=0;
        }
    }
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            string s;
            memset(v,0,sizeof(v));
            memset(vis,0,sizeof(vis));
            for(int i=0;i<6;i++)
            {
                cin>>s;
                for(int j=0;j<s.length();j++)
                {
                    if(s[j]=='h')
                        v[i][0]=1;
                    if(s[j]=='a')
                        v[i][1]=1;
                    if(s[j]=='r')
                        v[i][2]=1;
                    if(s[j]=='b')
                        v[i][3]=1;
                    if(s[j]=='i')
                        v[i][4]=1;
                    if(s[j]=='n')
                        v[i][5]=1;
                }        
            }
            cnt=0;
            flag=2;
            dfs(0);
            if(flag==1)
                cout<<"Yes"<<endl;
            else
                cout<<"No"<<endl;
        }
        return 0;
    }
  • 相关阅读:
    JS项目快速压缩(windows平台)
    Maven工程的POM继承
    Docker构建一个node镜像
    win10家庭版安装Docker for Windows
    linux,vim和bash命令小册
    vue文档阅读笔记——计算属性和侦听器
    nodejs的jekins部署
    `vue-router`的`History`模式下的项目发布
    花式图表,炫技时刻!PPT技能
    在创业之路上不断创新
  • 原文地址:https://www.cnblogs.com/-citywall123/p/11805633.html
Copyright © 2011-2022 走看看