赞
踩
Problem - D - Codeforceshttps://codeforces.com/contest/1607/problem/D
这道题采用了暴力和排序算法
首先要将int和char配成一对元素存入数组。由于未知原因如果使用vector,会在后期无法比较int元素的大小(待证明)
在参考了此文章思路后
但后来发现如果 3B 3R的情形,cnt已经更新到3 ,红色方块此时没有判断的条件了。
所以
正确的思路应该是先排序好数列,然后先将蓝色的进行操作,组成新数列里较小数的部分
再去排列红色的方块,如果大于cnt+1的话,因为后面的红色方块一定大于当前方块,则cnt+1这个数缺失,因此输出WRONG
此题的思路与之前的整理的BLOCKS类似
- void solve()
- {
- int n;
- cin >> n;
- for (int i = 0; i < n; i++)
- {
- cin >> a[i].first;
-
- }
- string s;
- cin >> s;
- for (int i = 0; i < n; i++)a[i].second = s[i];
- sort(a, a + n);
- int cnt = 0;
- for (int i = 0; i < n; i++)
- {
- if (a[i].second == 'B')
- {
- if (a[i].first <= cnt)
- {
- cout << "NO" << endl;
- return;
- }
- else if (a[i].first > cnt)
- {
- cnt++;
- }
- }
-
- }
- for (int i = 0; i < n; i++)
- {
- if (a[i].second == 'R')
- {
- if (a[i].first>cnt+1)
- {
- cout << "NO" << endl;
- return;
- }
- else
- {
- cnt++;
- }
- }
- }
-
- cout << "YES" << endl;
- return;
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。