洛谷 P1199 三國遊戲
阿新 • • 發佈:2020-09-01
頹多了,學一會兒
思路
貪心
小涵一定可以做到比計算機聰明,所以小涵不會輸,一定有答案。
小涵首先選擇的一定是默契值最大的兩位武將中的其中一個,而計算機之後一定會選擇與這個配對的另一個數(即默契值最大的兩位武將中的另一個),所以小涵在每一行都選擇不到最大值,只能選擇到次大值,所以對每一行的資料進行排序,找出次大值最大的即可。
程式碼
/* Name: P1199 三國遊戲 Author: Loceaner */ #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define int long long using namespace std; const int A = 5e2 + 11; const int B = 1e6 + 11; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; inline int read() { char c = getchar(); int x = 0, f = 1; for ( ; !isdigit(c); c = getchar()) if (c == '-') f = -1; for ( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return x * f; } int n, a[A][A], ans = 0; signed main() { n = read(); for (int i = 1; i < n; i++) for (int j = i + 1; j <= n; j++) { a[i][j] = a[j][i] = read(); } for (int i = 1; i <= n; i++) { sort(a[i] + 1, a[i] + 1 + n); ans = max(ans, a[i][n - 1]); } cout << 1 << '\n'; cout << ans << '\n'; }