Kattis - pizzahawaii 【状态标记】

Description

You are travelling in a foreign country. Although you are also open to eat some regional food, you just cannot resist after you have found an Italian restaurant which offers pizza. Unfortunately the menu is written in the foreign language, so the list of ingredients of the pizzas are incomprehensible to you. What will you do?

One thing that you notice is that each pizza has an Italian name, which sounds quite familiar to you. You even remember for each named pizza what the ingredients of this pizza usually are. You want to use that information to figure out what the possible meaning of each word on the list of ingredients is.

Input

The first line of the input gives the number of test cases t

(0< t≤20). The first line of each input gives the number n of pizzas on the menu (1≤n≤60). The following 3⋅n lines describe the pizzas on the menu. Each pizza description starts with one line containing the name of the pizza. The name of the pizza consists of between 3 and 20 uppercase and lowercase letters. The next line starts with an integer mi, giving the number of ingredients of the pizza on the menu (1≤mi≤20). The rest of the line contains the mi ingredients separated by spaces. Each ingredient is a word consisting of between 2 and 20

lowercase letters. The third line of each pizza description gives the ingredients in your native language in the same format. Note that the number of ingredients may differ, because each restaurant may use slightly different ingredients for pizzas with the same name, so the ingredients you remember for a pizza with that name may not match the actual ingredients.

Output

For each test case print all pairs of words (w1,w2

) where w1 is an ingredient in the foreign language that could be the same ingredient as w2 because w1 and w2 appear on the same set of pizzas. Sort the pairs in increasing lexicographical order by w1, and in case of a tie in increasing lexicographical order by w2

. Print a blank line between different test cases.

Sample Input 1

2

3

Hawaii

4 tomaten schinken ananas kaese

4 pineapple tomatoes ham cheese

QuattroStagioni

6 tomaten kaese salami thunfisch spinat champignons

6 mushrooms tomatoes cheese peppers ham salami

Capricciosa

6 champignons kaese tomaten artischocken oliven schinken

5 cheese tomatoes mushrooms ham artichoke

1

Funghi

3 tomaten kaese champignons

3 cheese tomatoes mushrooms

Sample Output 1

(ananas, pineapple)

(artischocken, artichoke)

(champignons, mushrooms)

(kaese, cheese)

(kaese, ham)

(kaese, tomatoes)

(oliven, artichoke)

(salami, peppers)

(salami, salami)

(spinat, peppers)

(spinat, salami)

(thunfisch, peppers)

(thunfisch, salami)

(tomaten, cheese)

(tomaten, ham)

(tomaten, tomatoes)

(champignons, cheese)

(champignons, mushrooms)

(champignons, tomatoes)

(kaese, cheese)

(kaese, mushrooms)

(kaese, tomatoes)

(tomaten, cheese)

(tomaten, mushrooms)

(tomaten, tomatoes)

题意

有一个人去旅行,然后发现那里的餐馆 有两份菜单。有一份是意大利语,还有一份是用英语写的。这个人就想通过几家餐馆不同的基本菜单,找出一部分意大利语与英语的对应关系。

思路

刚开始以为,一个一个对应就好了。 但是因为语法的不同,所以单词的位置可能不是一一对应的,而且可能存在一词多意。 所以不是这么简单一一对应。

但是有一个突破点就是,如果有一个单词在意大利语菜单当中出现了,那么在英语菜单当中的所有单词都可能与这个单词有对应关系。但是如果 英语菜单当中的单词 在另一本菜单中出现,而这个意大利单词没有在另一本菜单的对应菜单出现,那么说明,这两个词是一定没有关系的。

比如

A B C

D E F

G C D

D G H

我们通过第一组菜单 可以得出 A 与 D E F 都可能有对应关系。

但是 通过第二组菜单 发现 D 出现了 而 A 没有出现 所以 A 和 D 之间肯定是没有关系的。

可以通过这样的方法 来确定 但是比较繁琐

此时 我们可以引入状态标记

就是 在意大利语所有菜单中 一个单词出现的状态 如果和 英语所有菜单当中 一个单词出现的状态 一致的话 那么这两个单词是有对应关系的。

我们可以用二进制的 1 和 0 来表示状态

比如说

A B C

D E F

A G H

D F L

那么 A 的状态标记就是 1 1

D 和 F的状态标记也是 1 1 所以 A 和这两个单词是有对应关系的。

B C 的状态标记是 1 0

G H的状态标记是 0 1

等等

AC代码

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
const int MAX = 0x3f3f3f3f;
const int MIN = 0xc0c0c0c0;
const int maxn = 1e2 + 5;
string s[2][maxn][maxn];
int tot[2][maxn];
int main()
{
int t;
cin >> t;
map <string, string> m[2];
while (t--)
{
m[0].clear();
m[1].clear();
int n;
cin >> n;
string temp;
int i, j, k;
for (i = 0; i < n; i++)
{
cin >> temp;
for (j = 0; j < 2; j++)
{
scanf("%d", &tot[j][i]);
for (k = 0; k < tot[j][i]; k++)
{
cin >> s[j][i][k];
m[j][s[j][i][k]] = "#";
}
}
}
for (i = 0; i < 2; i++)
{
for (j = 0; j < n; j++)
{
for(k = 0; k < tot[i][j]; k++)
{
m[i][s[i][j][k]] += "1";
}
map <string, string>::iterator it;
for (it = m[i].begin(); it != m[i].end(); it++)
{
if (it -> second.size() != j + 2)
it -> second += "0";
}
}
}
map <string, string>::iterator it[2];
for (it[0] = m[0].begin(); it[0] != m[0].end(); it[0]++)
{
for (it[1] = m[1].begin(); it[1] != m[1].end(); it[1]++)
if (it[0]->second == it[1]->second)
cout << "(" << it[0]->first << ", " << it[1]->first << ")\n";
}
cout << endl;
}
}

Kattis - pizzahawaii 【状态标记】的更多相关文章

  1. ZOJ 3960 What Kind of Friends Are You? 【状态标记】

    题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3960 题意 首先给出 一系列名字 需要辨别的名字,然后给出Q个问 ...

  2. [SVN(ubuntu)] svn 文件状态标记含义

    A item 文件.目录或是符号链item预定加入到版本库. C item 文件item发生冲突,在从服务器更新时与本地版本发生交迭,在你提交到版本库前,必须手工的解决冲突. D item 文件.目录 ...

  3. iscroll横向滑动(当前页状态标记自动变化)

    var myScroll; function loaded(){ myScroll = new iScroll('wrapper',{ snap:true, checkDOMChanges:true, ...

  4. ZOJ - 3954 Seven-Segment Display 【状态标记】

    题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3954 题意 有一块 LED 灯 然后上面有七块灯管 在显示不同数 ...

  5. 浅谈Virtual Machine Manager(SCVMM 2012) cluster 过载状态检测算法

    在我们使用scvmm2012的时候,经常会看到群集状态变成了这样 点开看属性后,我们发现是这样 . 发现了吗?Over-committed,如果翻译过来就是资源过载,或者说资源过量使用了,那么这个状态 ...

  6. 【状态模式】 State Pattern

    我们先设计一个场景,饮料自动售卖机,来设计一下它的出售流程. 流程图中,我们可把这个过程看成几个状态: 投币状态,选择饮料状态,售出状态,出售完毕状态. ,有了这个四个状态,我们设计一下界面(很粗略) ...

  7. hdu 4057(ac自动机+状态压缩dp)

    题意:容易理解... 分析:题目中给的模式串的个数最多为10个,于是想到用状态压缩dp来做,它的状态范围为1-2^9,所以最大为2^10-1,那我们可以用:dp[i][j][k]表示长度为i,在tri ...

  8. JavaScript 应用开发 #4:切换任务的完成状态

    在勾选了任务项目左边的对号(复选框)以后,会将任务的状态标记为已完成,取消勾选的话,又会把任务的状态标记为未完成.所以, 我们需要一个可以切换任务完成状态的方法.在任务模型里面,表示任务状态的属性是 ...

  9. EF中的EntityState几个状态的说明

    之前使用EF,我们都是通过调用SaveChanges方法把增加/修改/删除的数据提交到数据库,但是上下文是如何知道实体对象是增加.修改还是删除呢?答案是通过EntityState枚举来判断的,我们看一 ...

随机推荐

  1. golang json数组拼接

    2016年06月16日 15:38:25 阅读数:2575 标签: golangjson数组 更多 个人分类: golang   func main() { a := []byte(`{"P ...

  2. ES6快速入门使用

    https://www.jianshu.com/p/061304806bda Babel-webpack的配置 Bebal官方文档 前段项目我想使用ES6的语法我应该怎么做呢?我们可以查看Babel的 ...

  3. 第二百一十八节,jQuery EasyUI,TimeSpinner(时间微调)组件

    jQuery EasyUI,TimeSpinner(时间微调)组件 学习要点: 1.加载方式 2.属性列表 3.事件列表 4.方法列表 本节课重点了解 EasyUI 中 TimeSpinner(时间微 ...

  4. 主干(trunk)、分支(branch )、标记(tag) 用法示例 + 图解

    以svn为例,git的master相当于trunk,dev分支相当于branches --------------------------------------------------------- ...

  5. 【C语言天天练(二)】预处理

    引言: 学C语言之初.一提到预处理,脑子里想到的就是#define的宏定义以及#include包括的头文件.后来随着对C的深入学习发现.预处理不止这些.比方条件编译.提前定义的宏等等.以下对此进行总结 ...

  6. C#实现动态编译代码

    /*------------------------------------------------------------------------------ * Copyright (C) 201 ...

  7. CentOS 7安装与配置jdk-8u162

    一.下载jdk-8u162版本 jdk-8u162-linux-x64.rpm 二.上传jdk到centos下 上传完后的文件如下,文件只有读写权限,没有执行权限 使用如下命令授权,如果文件已经有了执 ...

  8. 软件设计模式(Design pattern)(待续)

    软件设计模式是在面向对象的系统设计过程中反复出现的问题解决方案. 设计模式通常描述了一组相互紧密作用的类与对象. 设计模式提供一种讨论软件设计的公共语言,使得熟练设计者的设计经验可以被初学者和其他设计 ...

  9. HTTP错误 401.3

    这是在搭建ASP.NET运行环境时出现的错误,在开启了系统的IIS Web服务器,并安装完.NET FrameWork后, 输入网址:http://127.0.0.1  ,有时会出现401.3的错误, ...

  10. AngularJS 讲解,三 过滤器

    过滤器用来格式化需要展示给用户的数据.AngularJS有很多实用的内置过滤器,同时也提供了方便的途径可以自己创建过滤器. 在HTML中的模板绑定符号{{ }}内通过|符号来调用过滤器.例如:{{va ...