日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

hash:奶牛看地图(洛谷P3405 [USACO16DEC]Cities and States S)

發(fā)布時間:2023/12/3 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hash:奶牛看地图(洛谷P3405 [USACO16DEC]Cities and States S) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

洛谷傳送門

解析

其實就是每組2個長度為2的字符串統(tǒng)計交叉相等的個數(shù)
每個序列可以用一個26進制的數(shù)來表示,總要加個標(biāo)簽,勉強算hash。。(想叫《水題》 )
最大值為26*26(ZZ)
所以可以開一個二維數(shù)組來進行統(tǒng)計
那么就簡單了

代碼

#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<map> #include<vector> #include<queue> #include<stack> #include<deque> #include<set> #include<string> using namespace std; long long x[1050][1050]; int n; void solve(){for(int i=0;i<=1000;i++){for(int j=0;j<=1000;j++) x[i][j]=0;} } int main(){solve();char s[25],s1[3],s2[3];scanf("%d",&n);long long ans=0;int a,b;for(int i=1;i<=n;i++){scanf("%s%s",s,s1);a=26*(s[0]-'A')+(s[1]-'A');b=26*(s1[0]-'A')+(s1[1]-'A');if(a!=b){ans+=x[b][a];}x[a][b]++;}printf("%lld\n",ans);return 0; }

總結(jié)

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

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