日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

洛谷P3405 [USACO16DEC]Cities and States省市

發(fā)布時(shí)間:2023/12/20 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 洛谷P3405 [USACO16DEC]Cities and States省市 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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!

為了讓奶牛在智力上受到刺激,農(nóng)夫約翰在谷倉的墻上放了一張美國地圖。由于奶牛在谷倉里花了很多時(shí)間盯著這張地圖,他們開始注意到一些奇怪的關(guān)系。例如,城市Flint,在MI省,或者M(jìn)iami在FL省,他們有一種特殊的關(guān)系:“Flint”市前兩個(gè)字母就是“FL”省,邁阿密前兩個(gè)字母是“MI”省。

讓我們說,兩個(gè)城市是一個(gè)“特殊的一對”,如果他們滿足這個(gè)屬性,來自不同的省。奶牛想知道有多少特殊的城市存在。請幫助他們解決這個(gè)有趣的地理難題!

輸入輸出格式

輸入格式:

?

The first line of input contains?NN?(1 \leq N \leq 200,0001N200,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.

輸入的第一行包含(),地圖上的城市數(shù)量。

下一行包含兩個(gè)字符串:一個(gè)城市的名稱(字符串至少2個(gè)最多10個(gè)大寫字母),和它的兩個(gè)字母的州代碼(一串2個(gè)大寫字母)。注意狀態(tài)代碼可能像ZQ,這并不是一個(gè)真正的美國。同一名稱的多個(gè)城市可以存在,但它們將處于不同的州。

?

輸出格式:

?

Please output the number of special pairs of cities.

請輸出特殊城市對數(shù)。

?

輸入輸出樣例

輸入樣例#1:
6 MIAMI FL DALLAS TX FLINT MI CLEMSON SC BOSTON MA ORLANDO FL 輸出樣例#1:
1 /*樣例可以直接看成下面這個(gè)樣子的:MIFLDATXFLMICLSCBOMAORFL如果有滿足題意,那么就是MIFL 和 FLMI,那么,這里的有效數(shù)據(jù)只有四個(gè)字母,那么每一行我們就可以看作一個(gè)四位26進(jìn)制數(shù)!!維護(hù)兩個(gè)數(shù)組,一個(gè)hash1[456976],一個(gè)hash1[456976],具體456976是什么意思,是因?yàn)槿绻覀儗看做0,B看做1……Z看做25,那么最小的數(shù)AAAA=0,就是最大的數(shù)就是ZZZZ=((25*26+25)*26+25)*26+25=456975。那么,問題輕易解出——hash1表示原來的數(shù),hash2表示市編號和州編號翻轉(zhuǎn)后的表示的數(shù)。然后循環(huán)一遍,算出答案。注意此時(shí)算出的答案是兩倍的,因?yàn)槊總€(gè)算了兩遍。 */ #include<iostream> #include<cstdio> using namespace std; #define maxn 26*26*26*27 int n,h1[maxn],h2[maxn]; char s1[100],s2[100]; int main(){scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%s%s",s1+1,s2+1);if(s1[1]!=s2[1]||s1[2]!=s2[2]){int x1=(((s1[1]-'A')*26+s1[2]-'A')*26+s2[1]-'A')*26+s2[2]-'A';int x2=(((s2[1]-'A')*26+s2[2]-'A')*26+s1[1]-'A')*26+s1[2]-'A';h1[x1]++;h2[x2]++;}}long long ans=0;for(int i=0;i<maxn;i++)ans+=h1[i]*h2[i];ans/=2;cout<<ans; }

?

轉(zhuǎn)載于:https://www.cnblogs.com/thmyl/p/7512154.html

總結(jié)

以上是生活随笔為你收集整理的洛谷P3405 [USACO16DEC]Cities and States省市的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。