大家以后取最小值 min 的初始值无特殊情况建议不要设为 1e9。
在这次 ABC D 中,有:
1≤N≤109
WA Code: (WA 4)
#include <bits/stdc++.h>
using namespace std;
struct node{
int x,y;
char c;
}x[200010];
int len,n;
bool cmpx(node x,node y){return x.x < y.x;}
int main(){
cin >> len >> n;
for(int i = 1;i <= n;i++){
cin >> x[i].x >> x[i].y >> x[i].c;
}
sort(x+1,x+1+n,cmpx);
int mny = 1e9;//没错就是这里开了1e9
for(int i = 1;i <= n;i++){
if(x[i].c == 'W'){
mny = min(mny,x[i].y);
}else{
if(x[i].y >= mny){
cout << "No\n";
return 0;
}
}
}
cout << "Yes\n";
return 0;
}
AC Code:
#include <bits/stdc++.h>
using namespace std;
struct node{
int x,y;
char c;
}x[200010];
int len,n;
bool cmpx(node x,node y){
if(x.x != y.x) return x.x < y.x;
return x.y < y.y;
}
int main(){
cin >> len >> n;
for(int i = 1;i <= n;i++){
cin >> x[i].x >> x[i].y >> x[i].c;
}
sort(x+1,x+1+n,cmpx);
int mny = 1e9+10;//<-here
for(int i = 1;i <= n;i++){
if(x[i].c == 'W'){
mny = min(mny,x[i].y);
}else{
if(x[i].y >= mny){
cout << "No\n";
return 0;
}
}
}
cout << "Yes\n";
return 0;
}