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 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.

思路:

记录每个串的可用字符, DFS。

代码:

#include<bits/stdc++.h>
using namespace std;

const int MAXN = 2e6+10;

char s[6][MAXN];
int Vis[6][7];
int Use[7];
map<char, int> Mp;

bool Dfs(int step)
{
    //cout << step << endl;
    if (step == 7)
        return true;
    for (int i = 0;i < 6;i++)
    {
        if (Use[i] == 1 || Vis[i][step] == 0)
            continue;
        Use[i] = 1;
        if (Dfs(step+1))
            return true;
        Use[i] = 0;
    }
    return false;
}

int main()
{
    Mp['h'] = 1;
    Mp['a'] = 2;
    Mp['r'] = 3;
    Mp['b'] = 4;
    Mp['i'] = 5;
    Mp['n'] = 6;
    int t;
    scanf("%d", &t);
    while(t--)
    {
        memset(Use, 0, sizeof(Use));
        memset(Vis, 0, sizeof(Vis));
        for (int i = 0;i < 6;i++)
            scanf("%s", s[i]);
        for (int i = 0;i < 6;i++)
        {
            int len = strlen(s[i]);
            for (int j = 0;j < len;j++)
            {
                if (Mp[s[i][j]] == 0)
                    continue;
                Vis[i][Mp[s[i][j]]] = 1;
            }
        }
        /*
        for (int i = 0;i < 6;i++)
        {
            for (int j = 1;j <= 6;j++)
                cout << Vis[i][j] << ' ';
            cout << endl;
        }
        */
        if (Dfs(1))
            puts("Yes");
        else
            puts("No");
    }

    return 0;
}

原文地址:https://www.cnblogs.com/YDDDD/p/11797741.html

时间: 2024-11-05 22:58:56

The 2019 China Collegiate Programming Contest Harbin Site F. Fixing Banners的相关文章

The 2019 China Collegiate Programming Contest Harbin Site

目录 Contest Info Solutions A. Artful Paintings E. Exchanging Gifts F. Fixing Banners I. Interesting Permutation J. Justifying the Conjecture K. Keeping Rabbits L. LRU Algorithm Contest Info Practice Link Solved A B C D E F G H I J K L 6/12 O - - - O O

The 2019 China Collegiate Programming Contest Harbin Site K. Keeping Rabbits

链接: https://codeforces.com/gym/102394/problem/K 题意: DreamGrid is the keeper of n rabbits. Initially, the i-th (1≤i≤n) rabbit has a weight of wi. Every morning, DreamGrid gives the rabbits a carrot of weight 1 and the rabbits fight for the only carrot

The 2019 China Collegiate Programming Contest Harbin Site J. Justifying the Conjecture

链接: https://codeforces.com/gym/102394/problem/J 题意: The great mathematician DreamGrid proposes a conjecture, which states that: Every positive integer can be expressed as the sum of a prime number and a composite number. DreamGrid can't justify his c

The 2019 China Collegiate Programming Contest Harbin Site I. Interesting Permutation

链接: https://codeforces.com/gym/102394/problem/I 题意: DreamGrid has an interesting permutation of 1,2,-,n denoted by a1,a2,-,an. He generates three sequences f, g and h, all of length n, according to the permutation a in the way described below: For ea

The 2019 China Collegiate Programming Contest Harbin Site I - Interesting Permutation 思维

//#include<bits/stdc++.h> #include<map> #include<queue> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define int long long using namespace std; #define rep_1(i,m,n) for(int i=m;i<=n

The 2019 China Collegiate Programming Contest Harbin Site A - Artful Paintings 差分约束

#include<map> #include<queue> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define ll long long const int N=1e5+5; const int M=1e5+5; const int INF=0x3f3f3f3f; int read(

The 2019 China Collegiate Programming Contest Harbin Site E - Exchanging Gifts 拓扑图+离散化

非常难受的是,我用链表写的,要么wa,要么tle,甚至还出现了超内存... 然后换成矩阵,开始还是wa了两次,然后换了别的快读,才过,难受. #include<map> #include<queue> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; typedef long long ll; #

2019 China Collegiate Programming Contest Qinhuangdao Onsite

目录 Contest Info Solutions A. Angle Beats D. Decimal F. Forest Program I. Invoker J. MUV LUV EXTRA Contest Info Practice Link Solved A B C D E F G H I J K L 5/12 O - - O - O - - - O ? - O 在比赛中通过 ? 赛后通过 ! 尝试了但是失败了 - 没有尝试 Solutions A. Angle Beats 题意: 给出

2018 China Collegiate Programming Contest Final (CCPC-Final 2018)(A B G I L)

A:签到题,正常模拟即可. 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn = 1e5 + 5; 4 struct node{ 5 int id, time; 6 }; 7 node a[maxn]; 8 bool cmp(const node &a, const node &b){ 9 if(a.id^b.id) return a.id < b.id; 10 else return a.