E - Excting Secret Chamber at Mount Rushmore

By now you have probably heard that there is a spectacular stone sculpture featuring four famous U.S. presidents at Mount Rushmore. However, very few people know that this monument contains a secret chamber. This sounds like something out of a plot of a Hollywood movie, but the chamber really exists. It can be found behind the head of Abraham Lincoln and was designed to serve as a Hall of Records to store important historical U.S. documents and artifacts. Historians claim that the construction of the hall was halted in 1939 and the uncompleted chamber was left untouched until the late 1990s, but this is not the whole truth.

In 1982, the famous archaeologist S. Dakota Jones secretly visited the monument and found that the chamber actually was completed, but it was kept confidential. This seemed suspicious and after some poking around, she found a hidden vault and some documents inside. Unfortunately, these documents did not make any sense and were all gibberish. She suspected that they had been written in a code, but she could not decipher them despite all her efforts.

Earlier this week when she was in the area to follow the ACM-ICPC World Finals, Dr. Jones finally discovered the key to deciphering the documents, in Connolly Hall of SDSM&T. She found a document that contains a list of translations of letters. Some letters may have more than one translation, and others may have no translation. By repeatedly applying some of these translations to individual letters in the gibberish documents, she might be able to decipher them to yield historical U.S. documents such as the Declaration of Independence and the Constitution. She needs your help.

You are given the possible translations of letters and a list of pairs of original and deciphered words. Your task is to verify whether the words in each pair match. Two words match if they have the same length and if each letter of the first word can be turned into the corresponding letter of the second word by using the available translations zero or more times.
Input

The first line of input contains two integers m
(1≤m≤500) and n (1≤n≤50), where m is the number of translations of letters and n is the number of word pairs. Each of the next m lines contains two distinct space-separated letters a and b, indicating that the letter a can be translated to the letter b. Each ordered pair of letters (a,b) appears at most once. Following this are n lines, each containing a word pair to check. Translations and words use only lowercase letters ‘a’–‘z’, and each word contains at least 1 and at most 50

letters.
Output

For each pair of words, display yes if the two words match, and no otherwise.
Sample Input 1

9 5
c t
i r
k p
o c
r o
t e
t f
u h
w p
we we
can the
work people
it of
out the

Sample Output 1
yes
no
no
yes
yes

Sample Input 2
3 3
a c
b a
a b
aaa abc
abc aaa
acm bcm

Sample Output 2
yes
no
yes

题意:输入m和n,代表有m个翻译,和n句带翻译的两个单词,如果两个单词可以从前面的翻译成后面的,打印yes,否则no

//#include<bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stdlib.h>
#include<cstring>
#include<string.h>
#include<string>
#include<math.h>
using namespace std ;
typedef long long ll;
#define MAXN 1005
#define INF 0x3f3f3f3f // µÈÓÚ1061109567
#define MALL (Qnode *)malloc(sizeof(Qnode));

char sh[MAXN], ch[MAXN];
int Find[30][30];
int main()
{
    int n, m;
    cin >> n >> m;
    memset(Find, 0, sizeof(Find));
    char a, b;
    for(int i=0; i<n; ++i)
    {
        getchar();
        scanf("%c %c", &a, &b);
        Find[a-'a'][b-'a'] = 1;//建立关系
    }
    for(int i=0; i<26; ++i)
        for(int j=0; j<26; ++j)
            if(Find[i][j] == 1)//i能找到j
                for(int k=0; k<26; ++k)//如果k能找到i,则k也可以找到j
                    if(Find[k][i] == 1)
                        Find[k][j]=1;
 	 for(int l=0; l<m; ++l)
    {
        scanf("%s%s", sh, ch);
        int les = strlen(sh);
        int lec = strlen(ch);
        int i=0, j=0, flag=0;
        while(i<les && j<lec && flag==0)
        {
            if(sh[i] == ch[j] || Find[sh[i]-'a'][ch[j]-'a'])
            {
                i++;
                j++;
            }
            else
                flag=1;
        }
        if(les == lec && flag == 0)
            cout << "yes" << '\n';
        else
            cout << "no" << '\n';
    }
    return 0;
}
        

没啥好说的,我居然想到用树存。。。。。。然后dfs。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Go语言(也称为Golang)是由Google开发的一种静态强类型、编译型的编程语言。它旨在成为一门简单、高效、安全和并发的编程语言,特别适用于构建高性能的服务器和分布式系统。以下是Go语言的一些主要特点和优势: 简洁性:Go语言的语法简单直观,易于学习和使用。它避免了复杂的语法特性,如继承、重载等,转而采用组合和接口来实现代码的复用和扩展。 高性能:Go语言具有出色的性能,可以媲美C和C++。它使用静态类型系统和编译型语言的优势,能够生成高效的机器码。 并发性:Go语言内置了对并发的支持,通过轻量级的goroutine和channel机制,可以轻松实现并发编程。这使得Go语言在构建高性能的服务器和分布式系统时具有天然的优势。 安全性:Go语言具有强大的类型系统和内存管理机制,能够减少运行时错误和内存泄漏等问题。它还支持编译时检查,可以在编译阶段就发现潜在的问题。 标准库:Go语言的标准库非常丰富,包含了大量的实用功能和工具,如网络编程、文件操作、加密解密等。这使得开发者可以更加专注于业务逻辑的实现,而无需花费太多时间在底层功能的实现上。 跨平台:Go语言支持多种操作系统和平台,包括Windows、Linux、macOS等。它使用统一的构建系统(如Go Modules),可以轻松地跨平台编译和运行代码。 开源和社区支持:Go语言是开源的,具有庞大的社区支持和丰富的资源。开发者可以通过社区获取帮助、分享经验和学习资料。 总之,Go语言是一种简单、高效、安全、并发的编程语言,特别适用于构建高性能的服务器和分布式系统。如果你正在寻找一种易于学习和使用的编程语言,并且需要处理大量的并发请求和数据,那么Go语言可能是一个不错的选择。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值