链接:

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;
}

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

  1. The 2019 China Collegiate Programming Contest Harbin Site

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

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

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

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

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

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

  6. 2019 China Collegiate Programming Contest Qinhuangdao Onsite F. Forest Program(DFS计算图中所有环的长度)

    题目链接:https://codeforces.com/gym/102361/problem/F 题意 有 \(n\) 个点和 \(m\) 条边,每条边属于 \(0\) 或 \(1\) 个环,问去掉一 ...

  7. The 2017 China Collegiate Programming Contest, Hangzhou Site Solution

    A: Super_palindrome 题面:给出一个字符串,求改变最少的字符个数使得这个串所有长度为奇数的子串都是回文串 思路:显然,这个字符串肯定要改成所有奇数位相同并且所有偶数位相同 那统计一下 ...

  8. 2019 China Collegiate Programming Contest Qinhuangdao Onsite

    传送门 D - Decimal 题意: 询问\(\frac{1}{n}\)是否为有限小数. 思路: 拆质因子,看是不是只包含2和5即可,否则除不尽. Code #include <bits/st ...

  9. The 2015 China Collegiate Programming Contest A. Secrete Master Plan hdu5540

    Secrete Master Plan Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Othe ...

随机推荐

  1. LeetCode 142. 环形链表 II(Linked List Cycle II)

    142. 环形链表 II 142. Linked List Cycle II 题目描述 给定一个链表,返回链表开始入环的第一个节点.如果链表无环,则返回 null. 为了表示给定链表中的环,我们使用整 ...

  2. LeetCode 617. 合并二叉树(Merge Two Binary Trees)

    617. 合并二叉树 617. Merge Two Binary Trees 题目描述 给定两个二叉树,想象当你将它们中的一个覆盖到另一个上时,两个二叉树的一些节点便会重叠. 你需要将他们合并为一个新 ...

  3. C++ 获取系统当前时间(日历时)

    获取系统当前时间(日历时) //Linux & C++11 #include <chrono> #include <ctime> using namespace std ...

  4. 用jquery和php实现ajax异步请求响应

    ajax技术可以实现异步请求和响应,下面的是用jquery向一个php脚本发送异步请求,并得到响应. 第一步,准备好前台的html表单,和jquery实现的ajax请求 <html lang=& ...

  5. WUSTOJ 1296: JAM计数法(Java)

    题目链接:

  6. S04_CH03_QSPI烧写LINUX系统

    S04_CH03_QSPI烧写LINUX系统 3.1概述 3.2搭建硬件系统 本章硬件工程还是使用<S04_CH01_搭建工程移植LINUX/测试EMMC/VGA>所搭建的VIVADO工程 ...

  7. Android--图片剪裁

    调用系统Intent剪裁图片 /** * 调用系统Intent剪裁图片 * @param context * @param uri * @param w * @param h */ public st ...

  8. k8s安装ingress

    1. 环境准备 安装nginx-ingress-controller和backend cd /etc/yum.repos.d/mainfests 下载镜像的脚本 vi ingressnginx.sh ...

  9. 使用 react 的 hooks 进行全局的状态管理

    使用 react 的 hooks 进行全局的状态管理 React 最新正式版已经支持了 Hooks API,先快速过一下新的 API 和大概的用法. // useState,简单粗暴,setState ...

  10. vijo 1456最小总代价

    题意:中文题... 题解:状态比较多,可以说是状压的基础题吧,我们定义dp[i][j],j为一个二进制数,每位0表示接触过该物品,1表示没有接触过;j表示当前物品在谁手上.递推的顺序注意一下就好 ac ...