洛谷P3405 [USACO16DEC]Cities and States省市
P3405 [USACO16DEC]Cities and States省市
题目描述
To keep his cows intellectually stimulated, Farmer John has placed a large map of the USA on the wall of his barn. Since the cows spend many hours in the barn staring at this map, they start to notice several curious patterns. For example, the cities of Flint, MI and Miami, FL share a very special relationship: the first two letters of "Flint" give the state code ("FL") for Miami, and the first two letters of "Miami" give the state code ("MI") for Flint.
Let us say that two cities are a "special pair" if they satisfy this property and come from different states. The cows are wondering how many special pairs of cities exist. Please help them solve this amusing geographical puzzle!
为了让奶牛在智力上受到刺激,农夫约翰在谷仓的墙上放了一张美国地图。由于奶牛在谷仓里花了很多时间盯着这张地图,他们开始注意到一些奇怪的关系。例如,城市Flint,在MI省,或者Miami在FL省,他们有一种特殊的关系:“Flint”市前两个字母就是“FL”省,迈阿密前两个字母是“MI”省。
让我们说,两个城市是一个“特殊的一对”,如果他们满足这个属性,来自不同的省。奶牛想知道有多少特殊的城市存在。请帮助他们解决这个有趣的地理难题!
输入输出格式
输入格式:
The first line of input contains NN (1 \leq N \leq 200,0001≤N≤200,000), the number ofcities on the map.
The next NN lines each contain two strings: the name of a city (a string of at least 2 and at most 10 uppercase letters), and its two-letter state code (a string of 2 uppercase letters). Note that the state code may be something like ZQ, which is not an actual USA state. Multiple cities with the same name can exist, but they will be in different states.
输入的第一行包含(),地图上的城市数量。
下一行包含两个字符串:一个城市的名称(字符串至少2个最多10个大写字母),和它的两个字母的州代码(一串2个大写字母)。注意状态代码可能像ZQ,这并不是一个真正的美国。同一名称的多个城市可以存在,但它们将处于不同的州。
输出格式:
Please output the number of special pairs of cities.
请输出特殊城市对数。
输入输出样例
6
MIAMI FL
DALLAS TX
FLINT MI
CLEMSON SC
BOSTON MA
ORLANDO FL
1
/*
样例可以直接看成下面这个样子的: MIFL
DATX
FLMI
CLSC
BOMA
ORFL
如果有满足题意,那么就是MIFL 和 FLMI,那么,这里的有效数据只有四个字母,那么每一行我们就可以看作一个 四位26进制数!! 维护两个数组,一个hash1[456976],一个hash1[456976],具体456976是什么意思,是因为如果我们将A看做0,B看做1……Z看做25,那么最小的数AAAA=0,就是最大的数就是ZZZZ=((25*26+25)*26+25)*26+25=456975。那么,问题轻易解出——hash1表示原来的数,hash2表示市编号和州编号翻转后的表示的数。然后循环一遍,算出答案。注意此时算出的答案是两倍的,因为每个算了两遍。
*/
#include<iostream>
#include<cstdio>
using namespace std;
#define maxn 26*26*26*27
int n,h1[maxn],h2[maxn];
char s1[],s2[];
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%s%s",s1+,s2+);
if(s1[]!=s2[]||s1[]!=s2[]){
int x1=(((s1[]-'A')*+s1[]-'A')*+s2[]-'A')*+s2[]-'A';
int x2=(((s2[]-'A')*+s2[]-'A')*+s1[]-'A')*+s1[]-'A';
h1[x1]++;h2[x2]++;
}
}
long long ans=;
for(int i=;i<maxn;i++)ans+=h1[i]*h2[i];
ans/=;
cout<<ans;
}
洛谷P3405 [USACO16DEC]Cities and States省市的更多相关文章
- [USACO16DEC]Cities and States省市
题目:洛谷P3405. 题目大意:给你一些省市的名称(大写)和所在省的名称(两个大写字母),求有多少对城市满足:A城市的名字的前两个字母等于B城市所在省的名称,且A所在省的名称等于B城市的名字的前两个 ...
- 洛谷 P1715 [USACO16DEC]Lots of Triangles好多三角形 解题报告
P1715 [USACO16DEC]Lots of Triangles好多三角形 题目描述 农民约翰希望通过卖出他拥有的一部分土地来增加收入.他在这片土地上种了\(N\)棵树(\(3\le N\le ...
- 洛谷 P3184 [USACO16DEC]Counting Haybales数草垛
P3184 [USACO16DEC]Counting Haybales数草垛 题目描述 Farmer John has just arranged his NN haybales (1 \leq N ...
- 洛谷 1938 [USACO09NOV]找工就业Job Hunt
洛谷 1938 [USACO09NOV]找工就业Job Hunt 题目描述 Bessie is running out of money and is searching for jobs. Far ...
- [洛谷P3527] [POI2011]MET-Meteors
洛谷题目链接:[POI2011]MET-Meteors 题意翻译 Byteotian Interstellar Union有N个成员国.现在它发现了一颗新的星球,这颗星球的轨道被分为M份(第M份和第1 ...
- Java实现 洛谷 Car的旅行路线
输入输出样例 输入样例#1: 1 3 10 1 3 1 1 1 3 3 1 30 2 5 7 4 5 2 1 8 6 8 8 11 6 3 输出样例#1: 47.5 import java.util. ...
- 洛谷1640 bzoj1854游戏 匈牙利就是又短又快
bzoj炸了,靠离线版题目做了两道(过过样例什么的还是轻松的)但是交不了,正巧洛谷有个"大牛分站",就转回洛谷做题了 水题先行,一道傻逼匈牙利 其实本来的思路是搜索然后发现写出来类 ...
- 洛谷P1352 codevs1380 没有上司的舞会——S.B.S.
没有上司的舞会 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description Ural大学有N个职员,编号为1~N.他们有 ...
- 洛谷P1108 低价购买[DP | LIS方案数]
题目描述 “低价购买”这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:“低价购买:再低价购买”.每次你购买一支股票,你必须用低于你上次购买它的价格购买它 ...
随机推荐
- Machine Learning No.8: Clusting
1. K-means algorithm 2. K-means optimization objective 3. Random initialization
- ES6中的class 与prototype
一.定义构造函数 在以前的js中,生成一个对象实例,需要先定义构造函数,然后通过prototype 的方式来添加方法,在生成实例: function Person(){ this.name = &qu ...
- CodeForces - 540D Bad Luck Island —— 求概率
题目链接:https://vjudge.net/contest/226823#problem/D The Bad Luck Island is inhabited by three kinds of ...
- 【LeetCode】两个有序数组合成一个有序数组
a = [1,3,5,7,9]b = [2,4,6,8,10]c= [] while len(a) > 0: if len(b) == 0: c.extend(a) break min_num ...
- 一.编译nginx
前往nginx.org下载需要的nginx版本,解压之后目录如下: auto : 主要存放辅助configure脚本执行时的文件, 例如判定nginx支持的模块,操作系统可供nginx使用的特性等. ...
- cad定制快捷键
1.工具-自定义-编辑程序参数,改好之后,关闭. 2.在命令行输入:reinit-选择PGP文件-确定.
- RQNOJ 514 字串距离:dp & 字符串
题目链接:https://www.rqnoj.cn/problem/514 题意: 设有字符串X,我们称在X的头尾及中间插入任意多个空格后构成的新字符串为X的扩展串,如字符串X为”abcbcd”,则字 ...
- laravel基础课程---10、数据库基本操作(如何使用数据库)
laravel基础课程---10.数据库基本操作(如何使用数据库) 一.总结 一句话总结: 1.链接数据库:.env环境配置里面 2.执行数据库操作:DB::table('users')->up ...
- test pic重复
- listen 74
Genes Link Touch and Hearing Sound and touch may seem completely separate, except possibly when play ...