P9110
题面解释
有 辆车在 出发,对于 ,当 为 时,车从 开始往上走,当 为 时,车从 开始往右走。
思路
开桶。
因为出发时间不同,需要在放进桶时 需减去 ,再看对于不同方向的车有没有 ,若有,去除两个方向中车最少的(不排除 辆车并排走)。
CODE
注意:为防止 数组越界,统一加上 的数,然后建议开大数组。
#include <bits/stdc++.h>
using namespace std;
const int N = 3e7 + 10;
const int M = 1e6 + 5;
int x[N], y[N];
int main(){
int n;
cin>>n;
for(int i = 1;i <= n;i++){
int r, w, t;
cin>>r>>w>>t;
if(r == 1){// 向上
y[w - t + M] ++;
}
else{// 向右
x[w - t + M] ++;
}
}
int ans = 0;
for(int i = 0;i <= N;i++){
if(x[i] && y[i]){
ans += min(x[i], y[i]);
}
}
cout<<ans;
}