原题下载
答案:
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
int N, M;
string spotty[100], plain[100];
bool test_location(int j)
{
bool found_cow[2][4] = {0};
// found_cow[0] refers to spotty cows, and found_cow[1]
// refers to non-spotty cows.
for (int i=0; i<N; i++) {
if (spotty[i][j] == 'A') found_cow[0][0] = true;
if (spotty[i][j] == 'C') found_cow[0][1] = true;
if (spotty[i][j] == 'G') found_cow[0][2] = true;
if (spotty[i][j] == 'T') found_cow[0][3] = true;
}
for (int i=0; i<N; i++) {
if (plain[i][j] == 'A') found_cow[1][0] = true;
if (plain[i][j] == 'C') found_cow[1][1] = true;
if (plain[i][j] == 'G') found_cow[1][2] = true;
if (plain[i][j] == 'T') found_cow[1][3] = true;
}
for (int i = 0; i < 4; ++i) {
if (found_cow[0][i] && found_cow[1][i]) return false;
}
return true;
}
int main(void)
{
ifstream fin ("cownomics.in");
ofstream fout ("cownomics.out");
fin >> N >> M;
for (int i=0; i<N; i++) fin >> spotty[i];
for (int i=0; i<N; i++) fin >> plain[i];
int answer = 0;
for (int j=0; j<M; j++)
if (test_location(j)) answer++;
fout << answer << "\n";
return 0;
}

以上就是关于【USACO 2017 US Open Contest, Bronze Problem 2. Bovine Genomics】的解答,如需了解学校/赛事/课程动态,可至翰林教育官网获取更多信息。
往期文章阅读推荐:
2026 NOAI国际AI奥赛中国站即将开考!赛事地址&日程已出!
2027 USAAIO美国AI奥赛启动报名!MIT/谷歌/Jane Street集体站台!

© 2026. All Rights Reserved. 沪ICP备2023009024号-1