题解 CF1459A 【Red-Blue Shuffle】

Warriors_Cat

2020-12-23 16:19:44

Solution

[题面传送门](https://www.luogu.com.cn/problem/CF1459A)。 题意从这里看即可。 --- ### $Solution:$ 简单思维题。因为有 $n!$ 种排列方法,所以每种情况的概率都是一样的,于是只要考虑红比蓝大的个数与红比蓝小的个数即可,分别记为 $cntR$ 和 $cntB$。 如果 $cntR > cntB$,则答案为 `RED`;如果 $cntR < cnt B$,则答案为 `BLUE`;如果 $cntR = cntB$,则答案为 `EQUAL`。 over,时间复杂度为 $O(n)$。 --- ### $Code:$ 以下为赛时代码。 ```cpp #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <queue> #include <vector> #include <cmath> using namespace std; #define ll long long #define fi first #define se second #define y1 y_csyakioi_1 #define y0 y_csyakioi_0 #define dingyi int mid = l + r >> 1, ls = p << 1, rs = p << 1 | 1; inline int read(){ int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9'){ if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9'){ x = x * 10 + (ch ^ 48); ch = getchar(); } return x * f; } const int N = 1010; int n; struct node{ int r, b, k; }a[N]; inline void work(){ n = read(); for(int i = 1; i <= n; ++i) scanf("%1d", &a[i].r); for(int i = 1; i <= n; ++i) scanf("%1d", &a[i].b); for(int i = 1; i <= n; ++i){ if(a[i].r > a[i].b) a[i].k = 1; if(a[i].r < a[i].b) a[i].k = -1; if(a[i].r == a[i].b) a[i].k = 0; } int ans = 0; for(int i = 1; i <= n; ++i) ans += a[i].k; if(ans == 0) puts("EQUAL"); if(ans > 0) puts("RED"); if(ans < 0) puts("BLUE"); } int main(){ int t = read(); while(t--) work(); return 0; } ```