王吕泓 • 1年前
问题:谎牛计数
#include<iostream>
#include<algorithm>
using namespace std;
struct node{
int x;
char y;
};
bool cmp(node a,node b){
return a.x<b.x;
}
int n;
node q[1001];
int s[1001];
int main() {
cin >> n;
for(int i = 1; i<= n; i++)cin >> q[i].y >> q[i].x;
sort(q + 1, q + 1 + n,cmp);
for(int i =1; i <= n; i++) {
s[i]= s[i - 1];
if(q[i].y =='L')s[i]++;
}
int res = n;
for(int i = n,r = 0; i; i--) {
int j=i,t=0;
while(j&& q[j].x == q[i].x) {
if(q[j].y =='G')t++;
j--;
}
res = min(res, s[j] + r);
r+=t;
i=j+1;
}
cout << res << endl;
return 0;
}
评论: