目录
Problem 2. Non-Transitive Dice编辑
你好啊我又又又来了
要准备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![](https://i-blog.csdnimg.cn/blog_migrate/4c2a0cd6a2ad3bc348d2a919524d4c96.png)
#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;
}