1 solutions
-
0
题解
不难发现,我们需要做的是把 和 进行配对, 和 进行配对。
它们之间能配对的对数应该是两者之间的最小值。
所以答案即为
标程
#include<bits/stdc++.h> #define N 110000 using namespace std; char s[N]; int main(){ int n; scanf("%d", &n); scanf("%s", s + 1); int cntl = 0,cntr = 0,cntu = 0,cntd = 0; for(int i = 1; i <= n; i++){ cntl += s[i] == 'L'; cntr += s[i] == 'R'; cntu += s[i] == 'U'; cntd += s[i] == 'D'; } printf("%d", 2 * (min(cntl, cntr) + min(cntu, cntd))); return 0; }
- 1
Information
- ID
- 47
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 9
- Tags
- (None)
- # Submissions
- 9
- Accepted
- 5
- Uploaded By