蚂蚁感冒
思路:把相碰转换方向 等价替换为遇到穿过。求出感染蚂蚁的左边有几个向右和右边有几个向左即可
import java.util.Scanner;
//蚂蚁感冒
public class A {
static int[] a = new int[55];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i = 0 ; i < n; i++)
a[i] = sc.nextInt();
int ans = 1;
int left = 0;
int right = 0;
for(int i = 1; i < n; i++) {
if(a[i] > 0 && Math.abs(a[i]) < Math.abs(a[0]))
left++;
if(a[i] < 0 && Math.abs(a[i]) > Math.abs(a[0]))
right++;
}
if(a[0] > 0)
System.out.println(right == 0? 1 : ans + left + right);
else
System.out.println(left == 0? 1 : ans + left + right);
}
}