赞
踩
目录
Problem 2. Non-Transitive Dice编辑
这次是青铜的题解,
我还会写银组的哦!
:))
话不多说,上题解:
✓
题解
- #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;
- }
- #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";
- }
- }
- }
- #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;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。