sicily 1035. DNA matching
题意:判断基因链是否匹配,匹配的双链数加1,并要标记,下次比较不能重用!
解法: 打擂台法
1 #include<iostream> 2 #include<string> 3 #include<vector> 4 #include<cmath> 5 using namespace std; 6 7 bool compute(string s1, string s2){ 8 if(s1.length() != s2.length()) 9 return false; 10 bool flag = false; 11 for(int i=0;i<s1.length();i++){ 12 flag =(abs(s1[i]-s2[i]) == 19 || abs(s1[i]-s2[i]) == 4); 13 if(!flag) 14 break; 15 } 16 return flag; 17 } 18 vector<string> strands; 19 20 int main(){ 21 int caseNums; 22 cin >> caseNums; 23 while(caseNums--){ 24 int rows; 25 string temp; 26 int result =0; 27 28 cin >> rows; 29 strands.resize(rows); 30 strands.clear(); 31 for(int i=1;i<=rows;i++){ 32 cin >> temp; 33 strands.push_back(temp); 34 } 35 36 for(int i=0;i<strands.size();i++){ 37 if(strands[i] =="00") 38 continue; 39 for(int j=i+1;j<strands.size();j++){ 40 if(strands[j]=="0") 41 continue; 42 if(compute(strands[i],strands[j])) 43 { 44 strands[i] ="00"; 45 strands[j] ="00"; 46 result++; 47 break; 48 } 49 } 50 } 51 cout<<result<<endl; 52 } 53 return 0; 54 }