USACO 1月 2021-2022 January Contest Bronze 题解

目录

你好啊我又又又来了

要准备usaco的铁铁们可以参考这个文章哦!USACO题库 - 比Usaco Training更好用的网站_GeekAlice的博客-CSDN博客https://blog.csdn.net/GeekAlice/article/details/122291933

第一题

Problem 1. Herdle

第二题

Problem 2. Non-Transitive Dice​编辑

第三题

Problem 3. Drought


你好啊我又又又来了

要准备usaco的铁铁们可以参考这个文章哦!USACO题库 - 比Usaco Training更好用的网站_GeekAlice的博客-CSDN博客https://blog.csdn.net/GeekAlice/article/details/122291933

这次是青铜的题解,

我还会写银组的哦!

:))

话不多说,上题解:


第一题

Problem 1. Herdle

USACO 1月 2021-2022 January Contest Bronze 题解_第1张图片

       USACO 1月 2021-2022 January Contest Bronze 题解_第2张图片

USACO 1月 2021-2022 January Contest Bronze 题解_第3张图片

题解

  

#include
using namespace std;



#define MAXN 100
#define MOD 1000000007
int n, guess_count[26], actual_count[26], green, yellow;
string actual[3], guess[3];
string line; 
using namespace std;

int main(){
    for(int i=0;i<3;i++){
        cin>>actual[i];
        for(int j=0;j<3;j++){
            actual_count[actual[i][j]-'A']++;
        }
    }
    for(int i=0;i<3;i++){
        cin>>guess[i];
        for(int j=0;j<3;j++){
            guess_count[guess[i][j]-'A']++;
        }
    }
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            if(actual[i][j]==guess[i][j]){
                green++;
                guess_count[guess[i][j]-'A']--;
                actual_count[actual[i][j]-'A']--;
            }
        }
    }
    for(int i=0;i<26;i++){
        yellow+=min(actual_count[i],guess_count[i]);
    }
    cout<

第二题

Problem 2. Non-Transitive DiceUSACO 1月 2021-2022 January Contest Bronze 题解_第4张图片

 USACO 1月 2021-2022 January Contest Bronze 题解_第5张图片

#include 
using namespace std;

using Die = array;

bool beats(const Die& a, const Die& b) {
	int wins = 0, losses = 0;
	for(int i = 0; i < 4; i++) for(int j = 0; j < 4; j++) {
		if (a[i] > b[j]) ++wins;
		if (a[i] < b[j]) ++losses;
	}
	return wins > losses;
}

bool non_transitive(const Die& A, const Die& B) {
	for(int a = 1; a <= 10; a++) for(int b = 1; b <= 10; b++) for(int c = 1; c <= 10; c++) for(int d = 1; d <= 10; d++) {
		Die C{a,b,c,d};
		if (beats(A,B) && beats(B,C) && beats(C,A)) return 1;
		if (beats(B,A) && beats(C,B) && beats(A,C)) return 1;
	}
	return 0;
}

int main() {
	int N;
	cin >> N;
	for(int i = 0; i < N; i++) {
		Die A, B;
		for(int j = 0; j < 4; j++) cin >> A[j];
		for(int j = 0; j < 4; j++) cin >> B[j];
		if(non_transitive(A,B)) {
			cout << "yes\n";
		} else {
			cout << "no\n";
		}
	}
}

第三题

Problem 3. Drought

USACO 1月 2021-2022 January Contest Bronze 题解_第6张图片

 USACO 1月 2021-2022 January Contest Bronze 题解_第7张图片

#include
#define int long long
#define nl "\n"
using namespace std;

int exe(){
	int ans = 0, n;
	cin >> n; vector h(n);
	for (int& i : h) cin >> i;
	if (n == 1) return 0;
	for (int j : {1, 2}){
		for (int i = 1; i < n - 1; i++){
			if (h[i] > h[i - 1]){
				int dif = h[i] - h[i - 1];
				ans += 2 * dif, h[i + 1] -= dif, h[i] = h[i - 1];
			}
		}
		if (h[n - 1] > h[n - 2]) return -1;
		// now h is non-increasing
		reverse(h.begin(), h.end());
		// now h is non-decreasing
	}
	// now h is all equal
	return h[0] < 0 ? -1 : ans;
}

int main(){
	cin.tie(0)->sync_with_stdio(0); cin.exceptions(ios_base::failbit);
	int t; cin >> t;
	while (t--) cout << exe() << nl;
}

你可能感兴趣的:(USACO,Contest,算法,c++)