1211. 蚂蚁感冒
技巧:蚂蚁相撞反向行驶,可以看成是两个蚂蚁穿过了对方,这个不影响答案
#include<iostream>
using namespace std;
const int N = 60;
int a[N];
int n;
int main(){
cin >> n;
for(int i = 0; i < n; i ++) cin >> a[i];
int left = 0, right = 0;
for(int i = 1; i < n; i ++){
if(abs(a[i]) > abs(a[0]) && a[i] < 0) right ++;
if(abs(a[i]) < abs(a[0]) && a[i] > 0) left ++;
}
/*
a[0] > 0:
right > 0: left + right + 1;
right = 0: 1
a[0] < 0:
left > 0: left + right + 1;
left = 0: 1
*/
if(a[0] > 0 && right > 0 || a[0] < 0 && left > 0) cout << left + right + 1;
else cout << 1;
return 0;
}