原题链接https://www.luogu.com.cn/problem/P8611
模拟
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <tuple>
#include <vector>
#define ll long long
const ll N = 1e4 + 10;
ll n,m;
ll op[N];
ll dp[N][N];
ll dx[] = {0,-1};
ll dy[] = {-1,0};
struct ii{
ll a;
ll b;
}pp[N];
void solve(){
ll n;
std::cin >> n;
bool ok = false;
ll zz = 0;
for(ll i = 1; i <= n; i ++){
ll a;
std::cin >> a;
if(i == 1){
if(a > 0) ok = true;
else ok = false;
zz = std::abs(a);
}
pp[i] = {std::abs(a),a};
}
ll rre = 1;
bool jj = false;
if(ok){//往右走
for(ll i = 2; i <= n; i ++){
if(zz < pp[i].a && pp[i].b < 0){
jj = true;
rre ++;
}
}
if(jj == true){
for(ll i = 2; i <= n; i ++){
if(zz > pp[i].a && pp[i].b > 0){
rre ++;
}
}
}
std::cout << rre << "\n";
}
else{//感冒的是往左走的
for(ll i = 2; i <= n; i ++){
if(zz > pp[i].a && pp[i].b > 0){
jj = true;
rre ++;
}
}
if(jj == true){
for(ll i = 2; i <= n; i ++){
if(zz < pp[i].a && pp[i].b < 0){
rre ++;
}
}
}
std::cout << rre << "\n";
}
return ;
}
int main(){
ll t = 1;
while(t --)
solve();
return 0;
}