警示后人
  • 板块灌水区
  • 楼主Quartz_Blocks
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/12/28 22:00
  • 上次更新2024/12/29 11:18:52
查看原帖
警示后人
1059176
Quartz_Blocks楼主2024/12/28 22:00

大家以后取最小值 min 的初始值无特殊情况建议不要设为 1e9

在这次 ABC D 中,有:

1N1091 \le N \le 10^9

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;
}
2024/12/28 22:00
加载中...