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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 Tomb Raider(map+二进制枚举)

發(fā)布時間:2025/3/15 编程问答 10 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 Tomb Raider(map+二进制枚举) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

#1829 : Tomb Raider

時間限制:1000ms

單點時限:1000ms

內(nèi)存限制:256MB

描述

Lara Croft, the fiercely independent daughter of a missing adventurer, must push herself beyond her limits when she discovers the island where her father disappeared. In this mysterious island, Lara finds a tomb with a very heavy door. To open the door, Lara must input the password at the stone keyboard on the door. But what is the password? After reading the research notes written in her father's notebook, Lara finds out that the key is on the statue beside the door.

The statue is wearing many arm rings on which some letters are carved. So there is a string on each ring. Because the letters are carved on a circle and the spaces between any adjacent letters are all equal, any letter can be the starting letter of the string. The longest common subsequence (let's call it "LCS") of the strings on all rings is the password. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.

For example, there are two strings on two arm rings:?s1?= "abcdefg" and?s2?= "zaxcdkgb". Then "acdg" is a LCS if you consider 'a' as the starting letter of?s1, and consider 'z' or 'a' as the starting letter of?s2. But if you consider 'd' as the starting letter of?s1?and?s2, you can get "dgac" as a LCS. If there are more than one LCS, the password is the one which is the smallest in lexicographical order.

Please find the password for Lara.

輸入

There are no more than 10 test cases.

In each case:

The first line is an integer?n, meaning there are?n?(0 <?n?≤ 10) arm rings.

Then?n?lines follow. Each line is a string on an arm ring consisting of only lowercase letters. The length of the string is no more than 8.

輸出

For each case, print the password. If there is no LCS, print 0 instead.

樣例輸入

2 abcdefg zaxcdkgb 5 abcdef kedajceu adbac abcdef abcdafc 2 abc def

樣例輸出

acdg acd 0 #include<bits/stdc++.h> using namespace std;#define e exp(1) #define pi acos(-1) #define mod 998244353 #define inf 0x3f3f3f3f #define ll long long #define ull unsigned long long #define mem(a,b) memset(a,b,sizeof(a)) int gcd(int a,int b){return b?gcd(b,a%b):a;}int n,flag; string s; map<string,int> m,vis; vector<string> v; string sub(int x) {string index=s.substr(x);index+=s.substr(0,x);return index; } bool cmp(string a,string b) {if(a.length()==b.length())return a<b;return a.length()>b.length(); } int main() {while(~scanf("%d",&n)){m.clear();v.clear();flag=0;for(int cas=0; cas<n; cas++){cin>>s;int len=s.length();for(int l=0; l<len; l++){string s1=sub(l);for(int i=1; i<(1<<len); i++){string s2;for(int j=0; j<len; j++){if((1<<j)&i)s2+=s1[j];}if(vis[s2]==0){m[s2]++;vis[s2]=1;}}}vis.clear();}for(map<string,int>::iterator i=m.begin(); i!=m.end(); i++){if(i->second==n){v.push_back(i->first);flag=1;}}sort(v.begin(), v.end(), cmp);if(flag==0)puts("0");else cout<<v[0]<<endl;}return 0; }

?

總結(jié)

以上是生活随笔為你收集整理的ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 Tomb Raider(map+二进制枚举)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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