uva-10887-枚举
题意:集合S1和S2,把S2中的元素拼接到S1的后面去,生成新的元素,问有多少个不重复的元素
直接map.注意,不能用cin读取字符串,题目没有保证字符串中间没有空格
#include "pch.h"
#include <string>
#include<iostream>
#include<map>
#include<memory.h>
#include<vector> namespace cc
{
using std::cout;
using std::endl;
using std::cin;
using std::map;
using std::vector;
using std::string; int n;
int t;
int r, c;
int total;
constexpr int N = 1501;
string set1[N];
string set2[N];
map<string, int>allMaps;
void cal()
{
for (int i = 0;i < r;i++)
{
for (int j = 0;j < c;j++)
{
string str = set1[i] + set2[j];
if (allMaps[str] == 0)
{
++total;
allMaps[str] = 1;
}
}
}
}
void read()
{
total = 0;
allMaps.clear();
cin >> r >> c;
getchar();
for (int i = 0;i < r;i++)
getline(cin,set1[i]);
for (int i = 0;i < c;i++)
getline(cin, set2[i]); } void solve()
{
t = 1;
cin >> n;
while (n--)
{
read();
cal();
cout << "Case " << t << ": " << total << endl;
t++;
}
} }; int main()
{ #ifndef ONLINE_JUDGE
freopen("d://1.text", "r", stdin);
#endif // !ONLINE_JUDGE
cc::solve(); return 0;
}
uva-10887-枚举的更多相关文章
- UVa 12169 (枚举+扩展欧几里得) Disgruntled Judge
题意: 给出四个数T, a, b, x1,按公式生成序列 xi = (a*xi-1 + b) % 10001 (2 ≤ i ≤ 2T) 给出T和奇数项xi,输出偶数项xi 分析: 最简单的办法就是直接 ...
- UVa 140 (枚举排列) Bandwidth
题意较复杂,请参见原题=_=|| 没什么好说的,直接枚举每个排列就好了,然后记录最小带宽,以及对应的最佳排列. STL里的next_permutation函数真是好用. 比较蛋疼的就是题目的输入了.. ...
- UVa 1151 (枚举 + MST) Buy or Build
题意: 平面上有n个点,现在要把它们全部连通起来.现在有q个套餐,如果购买了第i个套餐,则这个套餐中的点全部连通起来.也可以自己单独地建一条边,费用为两点欧几里得距离的平方.求使所有点连通的最小费用. ...
- Even Parity UVA - 11464 (枚举)
从来没有觉得枚举有多费脑子的.但是这道题还是很香的. 思路:就是非常简单的枚举啦. 从一般的枚举开始考虑.一般的做法就是在所有的格子中有两种状态1, 0. 而一共有225个格子,所有一共要枚举的情 ...
- UVa 1354 枚举子集 Mobile Computing
只要枚举左右两个子天平砝码的集合,我们就能算出左右两个悬挂点到根悬挂点的距离. 但是题中要求找尽量宽的天平但是不能超过房间的宽度,想不到要怎样记录结果. 参考别人代码,用了一个结构体的vector,保 ...
- uva 10887
是个 hash 用的容器类水过 #include <iostream> #include <cstdio> #include <string> #include ...
- UVA 10887 Concatenation of Languages 字符串hash
题目链接:传送门 题意: 给你两个集合A,B,任意组合成新的集合C(去重) 问你最后C集合大小 题解: 暴力 组成的新串hash起来 #include<bits/stdc++.h> usi ...
- Uva 11754(枚举+中国剩余定理)
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #inclu ...
- UVA 10887 set或hash
题意: 给出n个A串和m个B串,将这A串与B串连接(B接在A后面)可以生成n*m个AB串,求不同的AB串的数量 分析: set直接水过 #include <bits/stdc++.h> u ...
- 几道hash题
1: UVa 10887 - Concatenation of Languages map 可以做 ,但是输入实在恶心,有空串之类的HASH模板: int Hash(char *s){ int s ...
随机推荐
- error: C++ preprocessor "/lib/cpp" fails sanity check错误解决方法
error: C++ preprocessor "/lib/cpp" fails sanity check 问题的解决 问题的根源是缺少必要的C++库.如果是CentOS系统,运行 ...
- [转]Python中出错:ImportError: No module named win32com.client
Python中出错:ImportError: No module named win32com.client [问题] [已解决]Python中处理操作Excel中的图表(Chart,Graph) 的 ...
- VSFTP再配置 我里个去马蛋网上这么多烂文章,走了好多弯路
1.CentOS 进行yum 安装 vsftpd 2.vi /etc/vsftpd/vsftpd.conf 进行配置 3.创建FTP 用户 # useradd –d /var/www -g ftp ...
- SQLSERVER2008 存储过程基本语法
SQLSERVER2008 存储过程基本语法 来源:https://www.cnblogs.com/tlduck/p/5462399.html 一.定义变量--简单赋值declare @a intse ...
- camtasis studio 未能创建视频内存资源。
camtasis studio failed to create a video memory resource.camtasis studio 未能创建视频内存资源. 在工具--选项中取消GPU加速 ...
- tomcat源码 分析 Catalina
通过查看分析启动脚本,发现最终调用的入口是org.apache.catalina.startup包下面的Bootstrap#main public static void main(String ar ...
- bzoj 4811: [Ynoi2017]由乃的OJ
树链剖分,用zkw线段树维护每条链两个方向上对每一位的变换情况,由于位数较少,可以用两个unsigned long long表示 #include<cstdio> typedef unsi ...
- P1616疯狂的采药
传送 它不是可爱的01背包了!!!这个题中一种药可以采无限次!!! 它进化成了完全背包.完全背包中的内循环从m到v[i]改成了从v[i]到m 既然如此,代码如下: #include<iostre ...
- 1127 ZigZagging on a Tree (30 分)
1127 ZigZagging on a Tree (30 分) Suppose that all the keys in a binary tree are distinct positive in ...
- host文件的工作原理及应用
host文件的工作原理及应用 Hosts文件是一个用于存储计算机网络中节点信息的文件,它可以将主机名映射到相应的IP地址,实现DNS的功能,它可以由计算机的用户进行控制. 一.Hosts文件基本介绍 ...