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

       

题解

  

#include<bits/stdc++.h>
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<<green<<endl;
    cout<<yellow;
}

第二题

Problem 2. Non-Transitive Dice

 

#include <bits/stdc++.h>
using namespace std;

using Die = array<int, 4>;

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

 

#include<bits/stdc++.h>
#define int long long
#define nl "\n"
using namespace std;

int exe(){
	int ans = 0, n;
	cin >> n; vector<int> 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;
}

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值