对于每组的数据,如果是公平的,那么两个能力值最高的人一定被分在了两组中。这个结论是显然的,因为如果被分在一组,那么一定会有一个人输,也就是不公平的。
有了这个结论,我们只需要判断能力最高的两人是否被分在同一组即可。对于一个数据类型 pair<int,int>,第一关键字为能力值,第二关键字为编号。首先通过 sort 函数用第一关键字进行排序,然后找到最后两项,若为第 $1,2$ 个人或第 $3,4$ 个人,也就是编号之和为 $3$ 或 $7$,则输出 NO;否则就是 YES。
这道题很简单,代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <cstring> #define init(x) memset (x,0,sizeof (x)) #define ll long long #define ull unsigned long long #define INF 0x3f3f3f3f using namespace std; const int MAX = 1e5 + 5; const int MOD = 1e9 + 7; inline int read (); int n;pair <int,int> a[5]; bool cmp (pair <int,int> x,pair <int,int> y); int main () { n = read (); for (int i = 1;i <= n;++i) { for (int j = 1;j <= 4;++j) a[j].first = read (),a[j].second = j; sort (a + 1,a + 1 + 4,cmp); if (a[3].second + a[4].second == 7 || a[3].second + a[4].second == 3) printf ("NO\n"); else printf ("YES\n"); } return 0; } inline int read () { int s = 0;int f = 1; char ch = getchar (); while ((ch < '0' || ch > '9') && ch != EOF) { if (ch == '-') f = -1; ch = getchar (); } while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0'; ch = getchar (); } return s * f; } bool cmp (pair <int,int> x,pair <int,int> y) { return x.first < y.first; }
|