BZOJ 4748: [Usaco2016 Dec]Cities and States

4748: [Usaco2016 Dec]Cities and States

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 123  Solved: 67
[Submit][Status][Discuss]

Description

To keep his cows intellectually stimulated, Farmer John has placed a large map of the USA on the wal l 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 r elationship: the first two letters of "Flint" give the state code ("FL") for Miami, and the first tw o 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!

Input

The first line of input contains N (1≤N≤200,000), the number of cities on the map.The next N lines  each contain two strings: the name of a city (a string of at least 2 and at most 10 uppercase lette rs), and its two-letter state code (a string of 2 uppercase letters). Note that the state code may b e 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.
依次给出N(1≤N≤200,000)个城市名及其州的代码(州代码保证仅有两位)。我们说,两个城市是一个“特殊对 ”,如果他们来自不同的州且A城市的州代码是B城市的城市名首两位,B城市的州代码是A城市的城市名首两位。问 :在给定的信息中有多少个“特殊对”?

Output

Please output the number of special pairs of cities.

Sample Input

6
MIAMI FL
DALLAS TX
FLINT MI
CLEMSON SC
BOSTON MA
ORLANDO FL

Sample Output

1

就26*26+26种可能字符

开桶记下就好了

没看到不同WA一发。。。


#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<map>
#include<set>
using namespace std;

typedef double db;

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
void print(int x)
{if(x<0)putchar('-'),x=-x;if(x>=10)print(x/10);putchar(x%10+'0');}

const int N=1000;

int mp[N][N];

char a[15],b[15];

int main()
{
	int n=read();long long ans=0;
	for(int i=1,A,B;i<=n;++i)
	{
		scanf("%s",a+1);
		scanf("%s",b+1);
		A=(a[1]-'A'+1)*26+a[2]-'A'+1;
		B=(b[1]-'A'+1)*26+b[2]-'A'+1;
		if(A==B)continue;
		ans+=mp[B][A];
		mp[A][B]++;
	}
	cout<<ans<<endl;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值